python smtp发送邮件

就是向数据中添加了一个值,类似字典映射

⑵ 如何在python中使用smtplib连接gmail发送邮件

单击"工具"菜单,然后选择"帐户..."。
单击"添加",然后单击"邮件..."
在"显示名:"字段中输入您的姓名,然后单击"下一步"。
在"电子邮件地址:"字段中输入您的完整 Gmail 电子邮件地址 ([email protected]),然后单击"下一步"。
在"接收邮件(POP3, IMAP 或 HTTP)服务器:"字段中输入"pop.gmail.com"。在"发送邮件服务器 (SMTP):"字段中输入"smtp.gmail.com"。
单击"下一步"。
在"帐户名:"字段中输入您的 Gmail 用户名(包括"@gmail.com")。在"密码:"字段中输入您的 Gmail 密码,然后单击"下一步"。
单击"完成"。
突出显示"帐户"下的"pop.gmail.com",并单击"属性"。
单击"高级"标签。
选中"发送邮件 (SMTP)"下"此服务器要求安全连接 (SSL)"旁边的复选框。
在"发送邮件 (SMTP):"字段中输入"465"。
选中"接收邮件 (POP3)"下"此服务器要求安全连接 (SSL)"旁边的复选框。此端口将更改为 995。
*"发送"和"接收"邮件服务器字段的顺序因版本而异。确保您在每一字段中输入了正确信息。

⑶ 如何使用Python发送带的邮件

.headerimportHeaderfromemail.mime.textimportMIMETextfromemail.utilsimportparseaddr,formataddrdefsend_email(from_addr,to_addr,subject,password):
msg=MIMEText("邮件正文",'html','utf-8')
msg['From']=u'<%s>'%from_addr
msg['To']=u'<%s>'%to_addr
msg['Subject']=subject

smtp=smtplib.SMTP_SSL('smtp.163.com',465)
smtp.set_debuglevel(1)
smtp.ehlo("smtp.163.com")
smtp.login(from_addr,password)
smtp.sendmail(from_addr,[to_addr],msg.as_string())if__name__=="__main__":
#这里的密码是开启smtp服务时输入的客户端登录授权码,并不是邮箱密码
#现在很多邮箱都需要先开启smtp才能这样发送邮件
send_email(u"from_addr",u"to_addr",u"主题",u"password")

⑷ python下smtpsendmail发送特别慢

我来回答你
s.sendmail(me, to_list, fullText)需要去连mailhost,mailhost就是邮件主机,连邮件主机会耗费时间。

⑸ 如何使用python发邮件

直接贴点代码,感受下

#!/usr/bin/python

#-*-coding:UTF-8-*-importsmtplib

fromemail.mime.textimportMIMEText

fromemail.headerimportHeadersender='XXXXX'
receivers=['[email protected]']#接收邮件,可设置为你的QQ邮箱或者其他邮箱#三个参数:第一个为文本内容,第二个plain设置文本格式,第三个utf-8设置编码

message=MIMEText('Python邮件发送测试...','plain','utf-8')

message['From']=Header("测试",'utf-8')

message['To']=Header("测试",'utf-8')subject='PythonSMTP邮件测试'

message['Subject']=Header(subject,'utf-8')

try:

smtpObj=smtplib.SMTP('localhost')

smtpObj.sendmail(sender,receivers,message.as_string())

print"邮件发送成功"

exceptsmtplib.SMTPException:

print"Error:无法发送邮件"

⑹ 如何通过Python使用SMTP发送邮件的代码

https://www.douban.com/note/354362421/
这种方式 邮件里如果有图片的话 只能以外链的形式。缺点是:有的邮件服务器默认禁用图片。
https://www.douban.com/note/605625422/
这个是把图片写到邮件内容里。

⑺ 如何通过python发送邮件啊

一般最好有个smtp服务器,比如说你在163注册个邮箱,这样可以用smtplib通过这个邮箱来发送。以下是示例:

#-*- coding:utf8 -*-
import smtplib
import email
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.mime.text import MIMEText

mail_host="smtp.163.com"
mail_user="yourusername"
mail_pass="yourpassword"
mail_postfix="mail.163.com"

def sendmail(to_list,sub,con):
"""发送邮件
"""
# translation
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"

msg = MIMEMultipart('related')
msg['Subject'] = email.Header.Header(sub,'utf-8')
msg['From'] = me
msg['To'] = ";".join(to_list)
msg.preamble = 'This is a multi-part message in MIME format.'

msgAlternative = MIMEMultipart('alternative')
msgText = MIMEText(con, 'plain', 'utf-8')
msgAlternative.attach(msgText)
msg.attach(msgAlternative)

try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.quit()

except Exception,e:
return False

return True

if __name__ == '__main__':
if sendmail(['[email protected]'],"测试","测试"):
print "Success!"
else:
print "Fail!"

如果要不经过邮件系统直接发,通常会被当作垃圾邮件扔了,所以还是这样吧。

⑻ python smtp邮件发送失败怎么办

以下代码调试通过:

#coding:utf-8
importsmtplib
fromemail.mime.textimportMIMEText
fromemail.headerimportHeader

sender='[email protected]'
receiver='[email protected]'
subject='pythonemailtest'
smtpserver='smtp.139.com'
username='[email protected]'
password='xxxxxx'

msg=MIMEText('你好','text','utf-8')#中文需参数‘utf-8',单字节字符不需要
msg['Subject']=Header(subject,'utf-8')

smtp=smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username,password)
smtp.sendmail(sender,receiver,msg.as_string())
smtp.quit()

运行效果:

⑼ 使用Python的smtp发送邮件失败

subject参数要写的正常一点,不要让对方一检测就觉得是垃圾邮件