简体   繁体   中英

Emails which are sent by python script drop in Spam on GMail

After registration on our service user is sent by email with confirmation link. But when it is sent to Gmail or other mail services it usually drops to spam. Here is the code:

def email_user(self, subject, message, from_email=None):
    send_mail(subject, message, from_email, [self.email])

def activate_email(self, email=None):

    if email: self.email = email

    self.is_activated = False
    self.activation_code = hashlib.sha256(str(self.email) + os.urandom(256)).hexdigest()[:32]
    self.save()

    subject = u'Welcome to the {0}!'.format(settings.SITE_NAME)
    message = render_to_string('users/emails/activation.html', {'activation_code': self.activation_code, 'site_name': settings.SITE_NAME, 'site_domain': settings.SITE_DOMAIN})

    self.email_user(subject, message, settings.SITE_EMAIL)

How to add DKIM or other license to this email in order to make Google trust to our server? We're using Zimbra mail server on our site domain.

PS I found this snippet: https://djangosnippets.org/snippets/1995/ Is it suitable somehow in my case or not?

Thank you!

How your mail is treated depends first and foremost on the configuration of the email server which sends the messages generated by your application, and the DNS records associated with it .

Google's guidelines for bulk senders are a great place to start. Check that your mail server (and the emails themselves) comply with the rules.

DKIM is one of these guidelines, so yes: adding DKIM signatures will help. A few other points in the guide:

  • "Use the same address in the 'From:' header on every bulk mail you send." If you used different From headers while testing or something, this could be the problem.
  • Publish an SPF record.
  • Publish a DMARC policy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM