本文整理汇总了Python中email.mime.text.MIMEText方法的典型用法代码示例。如果您正苦于以下问题:Python text.MIMEText方法的具体用法?Python text.MIMEText怎么用?Python text.MIMEText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.mime.text
的用法示例。
在下文中一共展示了text.MIMEText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_email
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def send_email(contact):
recipient = contact[recipient_column]
email_text = body_value if use_body_value else contact.get(body_column, "")
email_subject = subject_value if use_subject_value else contact.get(subject_column, "")
sender = sender_value if use_sender_value else contact.get(sender_column, "")
msg = MIMEMultipart()
msg["From"] = sender
msg["To"] = recipient
msg["Subject"]= email_subject
# Leave some space for proper displaying of the attachment
msg.attach(MIMEText(email_text + '\n\n', 'plain', body_encoding))
for a in mime_parts:
msg.attach(a)
s.sendmail(sender, [recipient], msg.as_string())
示例2: mail_send_with_details
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def mail_send_with_details(relay, sender, subject, to, text, xmailer=None, followup_to=None, dry=True):
import smtplib
from email.mime.text import MIMEText
import email.utils
msg = MIMEText(text, _charset='UTF-8')
msg['Subject'] = subject
msg['Message-ID'] = email.utils.make_msgid()
msg['Date'] = email.utils.formatdate(localtime=1)
msg['From'] = sender
msg['To'] = to
if followup_to:
msg['Mail-Followup-To'] = followup_to
if xmailer:
msg.add_header('X-Mailer', xmailer)
msg.add_header('Precedence', 'bulk')
if dry:
logger.debug(msg.as_string())
return
logger.info("%s: %s", msg['To'], msg['Subject'])
s = smtplib.SMTP(relay)
s.sendmail(msg['From'], {msg['To'], sender }, msg.as_string())
s.quit()
示例3: send_mail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def send_mail(to_email,message):
# 定义邮件发送
# Define send_mail() function
smtp_host = 'smtp.xxx.com'
# 发件箱服务器
# Outbox Server
from_email = 'from_email@xxx.com'
# 发件邮箱
# from_email
passwd = 'xxxxxx'
# 发件邮箱密码
# from_email_password
msg = MIMEText(message,'plain','utf-8')
msg['Subject'] = Header(u'Email Subject','utf-8').encode()
# 邮件主题
# Email Subject
smtp_server = smtplib.SMTP(smtp_host,25)
# 发件服务器端口
# Outbox Server Port
smtp_server.login(from_email,passwd)
smtp_server.sendmail(from_email,[to_email],msg.as_string())
smtp_server.quit()
示例4: sendfailmail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def sendfailmail():
try:
SUBJECT = 'QQ点赞机下线提醒'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例5: sendfailmail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def sendfailmail():
global QQUserName, MyUIN
try:
SUBJECT = 'QQ挂机下线提醒: '+str(QQUserName)+'[QQ号:'+str(MyUIN)+']'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please restart the program and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例6: smtpmail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def smtpmail(self,subinfo):
try:
SUBJECT = '来自 '+subinfo+'的留言'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText(self.content, 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception, e:
logging.error("error sending msg:"+str(e))
return False
示例7: sendfailmail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def sendfailmail():
try:
SUBJECT = 'QQ小黄鸡下线提醒'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例8: send_reset_email
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def send_reset_email(self):
expires = datetime.datetime.now() + reset_password_timeout
url = self.generate_reset_link()
body = ("A password reset for {} has been requested.\r\n".format(self.username),
"Navigate to {} to complete reset.".format(url),
"Expires on {}".format(expires.isoformat())
)
message = MIMEText('\r\n'.join(body))
message['Subject'] = "Password Reset Link for CASCADE on {}".format(settings.load()['server']['hostname'])
message['From'] = 'cascade@' + settings.load()['server']['hostname']
message['To'] = self.email
server = smtplib.SMTP(settings.load()['links']['smtp'])
server.set_debuglevel(1)
server.sendmail(message['From'], [self.email], message.as_string())
server.quit()
示例9: sendEmail
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def sendEmail(subject, body, credentials):
self = credentials[0]
password = credentials[1]
fromAddr = credentials[2]
toAddr = credentials[3]
msg = MIMEMultipart()
msg['From'] = fromAddr
msg['To'] = toAddr
msg['Subject'] = subject
msgText = MIMEText(body, 'html', 'UTF-8')
msg.attach(msgText)
server = SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(self, password)
text = msg.as_string()
server.sendmail(fromAddr, toAddr, text)
server.quit()
# --- Scraping Methods ---------------------------------------------------------
示例10: envia_relatorio_html_por_email
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def envia_relatorio_html_por_email(assunto, relatorio_html):
gmail_user = os.environ['GMAIL_FROM']
gmail_password = os.environ['GMAIL_PASSWORD']
to = os.environ['SEND_TO'].split(sep=';')
msg = MIMEText(relatorio_html, 'html')
msg['Subject'] = assunto
msg['From'] = gmail_user
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
for to_addrs in to:
msg['To'] = to_addrs
server.send_message(msg, from_addr=gmail_user, to_addrs=to_addrs)
print('Email enviado com sucesso')
return True
except Exception as ex:
print('Erro ao enviar email')
print(ex)
return False
示例11: send_message
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def send_message(self, to_user, title, body, **kwargs):
if self.ssl:
smtp_client = smtplib.SMTP_SSL()
else:
smtp_client = smtplib.SMTP()
smtp_client.connect(zvt_env['smtp_host'], zvt_env['smtp_port'])
smtp_client.login(zvt_env['email_username'], zvt_env['email_password'])
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(title).encode()
msg['From'] = "{} <{}>".format(Header('zvt').encode(), zvt_env['email_username'])
if type(to_user) is list:
msg['To'] = ", ".join(to_user)
else:
msg['To'] = to_user
msg['Message-id'] = email.utils.make_msgid()
msg['Date'] = email.utils.formatdate()
plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
msg.attach(plain_text)
try:
smtp_client.sendmail(zvt_env['email_username'], to_user, msg.as_string())
except Exception as e:
self.logger.exception('send email failed', e)
示例12: send_email
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def send_email(msg_to, msg_subject, msg_body, msg_from=None,
smtp_server='localhost', envelope_from=None,
headers={}):
if not msg_from:
msg_from = app.config['EMAIL_FROM']
if not envelope_from:
envelope_from = parseaddr(msg_from)[1]
msg = MIMEText(msg_body)
msg['Subject'] = Header(msg_subject)
msg['From'] = msg_from
msg['To'] = msg_to
msg['Date'] = formatdate()
msg['Message-ID'] = make_msgid()
msg['Errors-To'] = envelope_from
if request:
msg['X-Submission-IP'] = request.remote_addr
s = smtplib.SMTP(smtp_server)
s.sendmail(envelope_from, msg_to, msg.as_string())
s.close()
示例13: test_get_msg_from_string_multipart
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def test_get_msg_from_string_multipart(self):
msg = MIMEMultipart()
msg['Subject'] = 'Test multipart mail'
msg.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
adaptor = self.get_adaptor()
msg = adaptor.get_msg_from_string(MessageClass, msg.as_string())
self.assertEqual(
'base64', msg.wrapper.cdocs[1].content_transfer_encoding)
self.assertEqual(
'text/plain', msg.wrapper.cdocs[1].content_type)
self.assertEqual(
'utf-8', msg.wrapper.cdocs[1].charset)
self.assertEqual(
'YSB1dGY4IG1lc3NhZ2U=\n', msg.wrapper.cdocs[1].raw)
示例14: test_header_splitter
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def test_header_splitter(self):
eq = self.ndiffAssertEqual
msg = MIMEText('')
# It'd be great if we could use add_header() here, but that doesn't
# guarantee an order of the parameters.
msg['X-Foobar-Spoink-Defrobnit'] = (
'wasnipoop; giraffes="very-long-necked-animals"; '
'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"')
sfp = StringIO()
g = Generator(sfp)
g.flatten(msg)
eq(sfp.getvalue(), '''\
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
''')
示例15: test_binary_body_with_encode_noop
# 需要导入模块: from email.mime import text [as 别名]
# 或者: from email.mime.text import MIMEText [as 别名]
def test_binary_body_with_encode_noop(self):
# Issue 16564: This does not produce an RFC valid message, since to be
# valid it should have a CTE of binary. But the below works, and is
# documented as working this way.
bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
self.assertEqual(msg.get_payload(), bytesdata)
self.assertEqual(msg.get_payload(decode=True), bytesdata)
s = StringIO()
g = Generator(s)
g.flatten(msg)
wireform = s.getvalue()
msg2 = email.message_from_string(wireform)
self.assertEqual(msg.get_payload(), bytesdata)
self.assertEqual(msg2.get_payload(decode=True), bytesdata)
# Test the basic MIMEText class