Ejemplo n.º 1
0
 def post(self, request):
     self.serializer_class = TestSMTPConfigSerializer
     if not SysOptions.smtp_config:
         return self.error("Please setup SMTP config at first")
     try:
         send_email(smtp_config=SysOptions.smtp_config,
                    from_name=SysOptions.website_name_shortcut,
                    to_name=request.user.username,
                    to_email=request.data["email"],
                    subject="You have successfully configured SMTP",
                    content="You have successfully configured SMTP")
     except smtplib.SMTPResponseException as e:
         # guess error message encoding
         msg = b"Failed to send email"
         try:
             msg = e.smtp_error
             # qq mail
             msg = msg.decode("gbk")
         except Exception:
             msg = msg.decode("utf-8", "ignore")
         return self.error(msg)
     except Exception as e:
         msg = str(e)
         return self.error(msg)
     return self.success()
Ejemplo n.º 2
0
def send_email_async(from_name, to_email, to_name, subject, content):
    if not SysOptions.smtp_config:
        return
    try:
        send_email(smtp_config=SysOptions.smtp_config,
                   from_name=from_name,
                   to_email=to_email,
                   to_name=to_name,
                   subject=subject,
                   content=content)
    except Exception as e:
        logger.exception(e)
Ejemplo n.º 3
0
def send_email_async(from_name, to_email, to_name, subject, content):
    if not SysOptions.smtp_config:
        return
    try:
        send_email(smtp_config=SysOptions.smtp_config,
                   from_name=from_name,
                   to_email=to_email,
                   to_name=to_name,
                   subject=subject,
                   content=content)
    except Exception as e:
        logger.exception(e)
Ejemplo n.º 4
0
 def post(self, request):
     if not SysOptions.smtp_config:
         return self.error("Please setup SMTP config at first")
     try:
         send_email(smtp_config=SysOptions.smtp_config,
                    from_name=SysOptions.website_name_shortcut,
                    to_name=request.user.username,
                    to_email=request.data["email"],
                    subject="You have successfully configured SMTP",
                    content="You have successfully configured SMTP")
     except smtplib.SMTPResponseException as e:
         # guess error message encoding
         msg = b"Failed to send email"
         try:
             msg = e.smtp_error
             # qq mail
             msg = msg.decode("gbk")
         except Exception:
             msg = msg.decode("utf-8", "ignore")
         return self.error(msg)
     except Exception as e:
         msg = str(e)
         return self.error(msg)
     return self.success()