Currently I have a custom email notification implemented and it works when you post a comment you receive an email which notify you about the posted comment, now the thing is that this is happening internally in the system, so basically the staff (account_handler's
) are talking to each other and get notify via email.
Now the problem that I'm facing is that account_handlers
that leave a comment on my thread for example, all of us will receive an email and be notify that comment was made in that thread, but when I respond I'm not sending anything, so no returning email's when you reply to the comment in the thread, the emails are only going in one direction, so the question is how can I fix this?
In my model I'm using this code for comment email notification setup:
class LeadContact(models.Model):
# models here
account_handler = models.ForeignKey(User, blank=True, null=True, related_name='handling_leads',
on_delete=models.SET_NULL)
# some custom function here
def send_comment_posted_emails(self, comment):
comment_user = comment.user
comment_text = comment.comment
handler_user = self.account_handler
handler_email = handler_user.email
if handler_email is not None and handler_email != comment_user.email:
current_site = Site.objects.get_current()
leads_url = self.get_view_url() + "#CommentsDiv"
ctx = {"leads_url": leads_url, "site_name": current_site.name, "leads_sn": self.serial_number,
"poster_name": user_util.get_user_full_name_or_user_name(comment_user),
"comment_text": comment_text}
subject = render_to_string("vinclucms_sales/email/email_sales_comment_posted_subject.txt", ctx)
subject = "".join(subject.splitlines())
message = render_to_string("vinclucms_sales/email/email_sales_comment_posted_message.html", ctx)
MailManager.send_mail_with_error_handler(subject, message, settings.DEFAULT_FROM_EMAIL, [handler_email],
message_html=message)
class Meta:
# Meta code here
Signal which is sending email:
@receiver(post_save, sender=EmailAddress)
def handle_email_address_save(sender, instance, created, update_fields, **kwargs):
confirm = account_settings.ACCOUNT_EMAIL_CONFIRMATION_EMAIL
must_confirm = instance.must_confirm if hasattr(instance, 'must_confirm') else False
warning("handle_email_address_save called for email "
+ str(instance.email) + ", created = " + str(created)
+ ", confirm = " + str(confirm) + ", must_confirm = " + str(must_confirm))
if confirm and not instance.verified and must_confirm:
instance.send_confirmation()
warning("handle_email_address_save sent confirmation")
# TODO: move to signals.py in quotes module
@receiver(comment_was_posted)
def handle_comment_posted(sender, comment, request, **kwargs):
if comment.content_type.model == 'leadcontact':
leadcontac = LeadContact.objects.get(pk=comment.object_pk)
leadcontac.send_comment_posted_emails(comment)