def send_plain_email(smtphost, username, password, fromEmail, toEmail, content, headers, senderDomainName=None, port=25, requireSSL=True): requireAuth = bool(password) msg = MIMEText(content) # Setup the mail headers for (header, value) in headers.items(): msg[header] = value headkeys = [k.lower() for k in headers.keys()] # Add required headers if not present if "message-id" not in headkeys: msg["Message-ID"] = messageid() if "date" not in headkeys: msg["Date"] = rfc822date() if "from" not in headkeys and "sender" not in headkeys: msg["From"] = fromEmail if "to" not in headkeys and "cc" not in headkeys and "bcc" not in headkeys: msg["To"] = toEmail # send message f = StringIO(msg.as_string()) d = defer.Deferred() factory = ESMTPSenderFactory(username, password, fromEmail, toEmail, f, d, requireAuthentication=requireAuth, requireTransportSecurity=requireSSL) if senderDomainName is not None: factory.domain = senderDomainName connectTCP(smtphost, port, factory) return d
def send_plain_email(fromEmail, toEmail, content, headers): if REQUIRE_AUTH: password = FilePath(SMTP_PASSWORD_PATH).getContent().strip() else: password = None msgstr = compose_plain_email(fromEmail, toEmail, content, headers) f = StringIO(msgstr) d = defer.Deferred() factory = ESMTPSenderFactory(SMTP_USERNAME, password, fromEmail, toEmail, f, d, requireAuthentication=REQUIRE_AUTH, requireTransportSecurity=REQUIRE_TRANSPORT_SECURITY) factory.domain = SENDER_DOMAIN connectTCP(SMTP_HOST, SMTP_PORT, factory) return d
def send_plain_email(fromEmail, toEmail, content, headers): if REQUIRE_AUTH: password = FilePath(SMTP_PASSWORD_PATH).getContent().strip() else: password = None msg = MIMEText(content) # Setup the mail headers for (header, value) in headers.items(): msg[header] = value headkeys = [k.lower() for k in headers.keys()] # Add required headers if not present if "message-id" not in headkeys: msg["Message-ID"] = messageid() if "date" not in headkeys: msg["Date"] = rfc822date() if "from" not in headkeys and "sender" not in headkeys: msg["From"] = fromEmail if "to" not in headkeys and "cc" not in headkeys and "bcc" not in headkeys: msg["To"] = toEmail if "reply-to" not in headkeys: msg["Reply-To"] = SUPPORT_ADDRESS if "user-agent" not in headkeys: msg["User-Agent"] = USER_AGENT if "content-type" not in headkeys: msg["Content-Type"] = CONTENT_TYPE # send message f = StringIO(msg.as_string()) d = defer.Deferred() factory = ESMTPSenderFactory( SMTP_USERNAME, password, fromEmail, toEmail, f, d, requireAuthentication=REQUIRE_AUTH, requireTransportSecurity=REQUIRE_TRANSPORT_SECURITY) factory.domain = SENDER_DOMAIN connectTCP(SMTP_HOST, SMTP_PORT, factory) return d
def send_email(self, to_addr, subject, content): msg = self.message(to_addr, subject, content) d = defer.Deferred() factory = ESMTPSenderFactory(self.username, self.password, self.from_addr, to_addr, msg, d, requireTransportSecurity=False) if self.senderDomainName is not None: factory.domain = self.senderDomainName reactor.connectTCP(self.smtphost, self.port, factory) return d
def send_plain_email(fromEmail, toEmail, content, headers): if REQUIRE_AUTH: password = FilePath(SMTP_PASSWORD_PATH).getContent().strip() else: password = None msg = MIMEText(content) # Setup the mail headers for (header, value) in headers.items(): msg[header] = value headkeys = [k.lower() for k in headers.keys()] # Add required headers if not present if "message-id" not in headkeys: msg["Message-ID"] = messageid() if "date" not in headkeys: msg["Date"] = rfc822date() if "from" not in headkeys and "sender" not in headkeys: msg["From"] = fromEmail if "to" not in headkeys and "cc" not in headkeys and "bcc" not in headkeys: msg["To"] = toEmail if "reply-to" not in headkeys: msg["Reply-To"] = SUPPORT_ADDRESS if "user-agent" not in headkeys: msg["User-Agent"] = USER_AGENT if "content-type" not in headkeys: msg["Content-Type"] = CONTENT_TYPE # send message f = StringIO(msg.as_string()) d = defer.Deferred() factory = ESMTPSenderFactory(SMTP_USERNAME, password, fromEmail, toEmail, f, d, requireAuthentication=REQUIRE_AUTH, requireTransportSecurity=REQUIRE_TRANSPORT_SECURITY) factory.domain = SENDER_DOMAIN connectTCP(SMTP_HOST, SMTP_PORT, factory) return d
def send_plain_email(fromEmail, toEmail, content, headers): if REQUIRE_AUTH: password = FilePath(SMTP_PASSWORD_PATH).getContent().strip() else: password = None msgstr = compose_plain_email(fromEmail, toEmail, content, headers) f = StringIO(msgstr) d = defer.Deferred() factory = ESMTPSenderFactory( SMTP_USERNAME, password, fromEmail, toEmail, f, d, requireAuthentication=REQUIRE_AUTH, requireTransportSecurity=REQUIRE_TRANSPORT_SECURITY) factory.domain = SENDER_DOMAIN connectTCP(SMTP_HOST, SMTP_PORT, factory) return d