python发邮件中文(python发送邮件,附件中文命名,怎么破)

1.python 发送邮件,附件中文命名,怎么破

不知道你是不是用的smtp来发的,我的发中文的附件没问题 #coding=utf-8'''Created on 2014-11-03@author: Neo'''import smtplibfrom email.mime.text import MIMEText import email.mime.multipartfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEBase import MIMEBasefrom email import Encoders#你自己修改下xxx的部分mailto_list = ['xxx@xxx.com']mail_host = "smtp.xxx.com" # 设置服务器mail_user = "xxxx" # 用户名mail_pass = "xxxxx" # 口令 mail_postfix = "xxxx.com" # 发件箱的后缀def send_mail(): me = "Hello" + "<" + mail_user + "@" + mail_postfix + ">" # 这里的hello可以任意设置,收到信后,将按照设置显示 content = 'Plz get the attachment!' msg = MIMEMultipart() body = MIMEText(content, _subtype='html', _charset='gb2312') # 创建一个实例,这里设置为html格式邮件 msg.attach(body) msg['Subject'] = "Test" # 设置主题 msg['From'] = me msg['To'] = ";".join(mailto_list) part = MIMEBase('application', 'octet-stream') # 读入文件内容并格式化,此处文件为当前目录下,也可指定目录 例如:open(r'/tmp/123.txt','rb') part.set_payload(open(u'test中文.txt','rb').read()) Encoders.encode_base64(part) ## 设置附件头 part.add_header('Content-Disposition', u'attachment; filename="test中文.txt"') msg.attach(part) try: s = smtplib.SMTP() s.connect(mail_host) # 连接smtp服务器 s.login(mail_user, mail_pass) # 登陆服务器 s.sendmail(me, mailto_list, msg.as_string()) # 发送邮件 s.close() print 'send mail sucess' return True except Exception, e: print str(e) return False send_mail()测试,发送ok。

python发邮件中文名,pythonoutlook发邮件,python自动发邮件

2.python 发送邮件,附件中文命名,怎么破

不知道你是不是用的smtp来发的,我的发中文的附件没问题

#coding=utf-8

'''

Created on 2014-11-03

@author: Neo

'''

import smtplib

from email.mime.text import MIMEText

import email.mime.multipart

from email.MIMEMultipart import MIMEMultipart

from email.MIMEBase import MIMEBase

from email import Encoders

#你自己修改下xxx的部分

mailto_list = ['xxx@xxx.com']

mail_host = "smtp.xxx.com" # 设置服务器

mail_user = "xxxx" # 用户名

mail_pass = "xxxxx" # 口令

mail_postfix = "xxxx.com" # 发件箱的后缀

def send_mail():

me = "Hello" + "<" + mail_user + "@" + mail_postfix + ">;" # 这里的hello可以任意设置,收到信后,将按照设置显示

content = 'Plz get the attachment!'

msg = MIMEMultipart()

body = MIMEText(content, _subtype='html', _charset='gb2312') # 创建一个实例,这里设置为html格式邮件

msg.attach(body)

msg['Subject'] = "Test" # 设置主题

msg['From'] = me

msg['To'] = ";".join(mailto_list)

part = MIMEBase('application', 'octet-stream')

# 读入文件内容并格式化,此处文件为当前目录下,也可指定目录 例如:open(r'/tmp/123.txt','rb')

part.set_payload(open(u'test中文.txt','rb').read())

Encoders.encode_base64(part)

## 设置附件头

part.add_header('Content-Disposition', u'attachment; filename="test中文.txt"')

msg.attach(part)

try:

s = smtplib.SMTP()

s.connect(mail_host) # 连接smtp服务器

s.login(mail_user, mail_pass) # 登陆服务器

s.sendmail(me, mailto_list, msg.as_string()) # 发送邮件

s.close()

print 'send mail sucess'

return True

except Exception, e:

print str(e)

return False

send_mail()测试,发送ok

中文,发邮件,python

3.如何用python发送email

python发邮件的库基于

import smtplib

from email.mime.text import MIMEText

from email.header import Header一般普通邮件的形式如下:

sender = '***'

receiver = '***'

subject = 'python email test'

smtpserver = 'smtp.163.com'

username = '***'

password = '***'

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

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

smtp = smtplib.SMTP()

smtp.connect('smtp.163.com')

smtp.login(username, password)

smtp.sendmail(sender, receiver, msg.as_string())

smtp.quit()

4.如何在python程序中发邮件

比如我用自己的 139 邮箱 lucia_gaga@139.com发送邮件到网易邮箱 也是我的办公邮箱 lu.han@beebank.com以下代码调试通过:# coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Headersender = 'lucia_gaga@139.com'receiver = 'lu.han@beebank.com'subject = 'python email test'smtpserver = 'smtp.139.com'username = 'lucia_gaga@139.com'password = 'xxxxxxxx'msg = MIMEText('你好 lucia 这是你的第一封 python 发出的邮件', '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()运行结果:。

5.如何在python程序中发邮件

通过命令行发送邮件,功能强大 python ./mail -s $server -f $from -t $to -u $user -p $pass -S "$subject" -m "${mail_msg}" -F $file Python 发送邮件可以添加附件:#!/usr/bin/python from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email import Utils, Encoders import mimetypes, sys,smtplib,socket,getopt class SendMail:def __init__(self,smtp_server,from_addr,to_addr,user,passwd):self.mailserver=smtp_server self.from_addr=from_addr self.to_addr=to_addr self.username=user self.password=passwd def attachment(self,filename):fd=open(filename,'rb') filename=filename.split('/') mimetype,mimeencoding=mimetypes.guess_type(filename[-1]) if (mimeencoding is None) or (mimetype is None):mimetype='application/octet-stream' maintype,subtype=mimetype.split('/') if maintype=='text':retval=MIMEText(fd.read(), _subtype=subtype, _charset='utf-8') else:retval=MIMEBase(maintype,subtype) retval.set_payload(fd.read()) Encoders.encode_base64(retval) retval.add_header('Content-Disposition','attachment',filename=filename[-1]) fd.close() return retval def msginfo(self,msg,subject,filename):# message = """Hello, ALL#This is test message.#--Anonymous""" message=msg msg=MIMEMultipart() msg['To'] = self.to_addr msg['From'] = 'sa <'+self.from_addr+'>' msg['Date'] = Utils.formatdate(localtime=1) msg['Message-ID'] = Utils.make_msgid() if subject:msg['Subject'] = subject if message:body=MIMEText(message,_subtype='plain') msg.attach(body)#for filename in sys.argv[1:]:if filename:msg.attach(self.attachment(filename)) return msg.as_string() def send(self,msg=None,subject=None,filename=None):try:s=smtplib.SMTP(self.mailserver) try:s.login(self.username,self.password) except smtplib.SMTPException,e:print "Authentication failed:",e sys.exit(1) s.sendmail(self.from_addr,self.to_addr.split(','),self.msginfo(msg,subject,filename)) except (socket.gaierror,socket.error,socket.herror,smtplib.SMTPException),e:print "*** Your message may not have been sent!" print e sys.exit(2) else:print "Message successfully sent to %d recipient(s)" %len(self.to_addr) if __name__=='__main__':def usage():print """Useage:%s [-h] -s -f -t -u -p [-S -m -F ] Mandatory arguments to long options are mandatory for short options too.-f, --from= Sets the name of the "from" person (i.e., the envelope sender of the mail).-t, --to= Addressee's address. -t "test@test.com,test1@test.com".-u, --user= Login SMTP server username.-p, --pass= Login SMTP server password.-S, --subject= Mail subject.-m, --msg= Mail message.-m "msg, 。

."-F, --file= Attachment file name.-h, --help Help documen. """ %sys.argv[0] sys.exit(3) try:options,args=getopt.getopt(sys.argv[1:],"hs:f:t:u:p:S:m:F:","--help --server= --from= --to= --user= --pass= --subject= --msg= --file=",) except getopt.GetoptError:usage() sys.exit(3) server=None from_addr=None to_addr=None username=None password=None subject=None filename=None msg=None for name,value in options:if name in ("-h","--help"):usage() if name in ("-s","--server"):server=value if name in ("-f","--from"):from_addr=value if name in ("-t","--to"):to_addr=value if name in ("-u","--user"):username=value if name in ("-p","--pass"):password=value if name in ("-S","--subject"):subject=value if name in ("-m","--msg"):msg=value if name in ("-F","--file"):filename=value if server and from_addr and to_addr and username and password:test=SendMail(server,from_addr,to_addr,username,password) test.send(msg,subject,filename) else:usage()。

6.如何用Python发邮件

文件形式的邮件 [python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header sender = '***' receiver = '***' subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' msg = MIMEText('你好','text','utf-8')#中文需参数'utf-8',单字节字符不需要 msg['Subject'] = Header(subject, 'utf-8') smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() HTML形式的邮件[python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.text import MIMEText sender = '***' receiver = '***' subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' msg = MIMEText('

你好

','html','utf-8') msg['Subject'] = subject smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() 带图片的HTML邮件[python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage sender = '***' receiver = '***' subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' msgRoot = MIMEMultipart('related') msgRoot['Subject'] = 'test message' msgText = MIMEText('Some HTML text and an image.good!','html','utf-8') msgRoot.attach(msgText) fp = open('h:\\python\\1.jpg', 'rb') msgImage = MIMEImage(fp.read()) fp.close() msgImage.add_header('Content-ID', '') msgRoot.attach(msgImage) smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msgRoot.as_string()) smtp.quit() 带附件的邮件[python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage sender = '***' receiver = '***' subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' msgRoot = MIMEMultipart('related') msgRoot['Subject'] = 'test message' #构造附件 att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="1.jpg"' msgRoot.attach(att) smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msgRoot.as_string()) smtp.quit() 群邮件[python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.text import MIMEText sender = '***' receiver = ['***','****',……] subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' msg = MIMEText('你好','text','utf-8') msg['Subject'] = subject smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() 各种元素都包含的邮件[python] view plaincopy#!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage sender = '***' receiver = '***' subject = 'python email test' smtpserver = 'smtp.163.com' username = '***' password = '***' # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Link" # Create the body of the message (a plain-text and an HTML version). text = "Hi!\nHow are you?\nHere is the link you wanted:\n = """\ <body> Hi! How are you? Here is the link you wanted. """ # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) #构造附件 att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attach。

7.如何用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(['test@test.com'],"测试","测试"):

print "Success!"

else:

print "Fail!"

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

8.到底怎么才能成功用python smtplib发送邮件

单击"工具"菜单,然后选择"帐户。"。

单击"添加",然后单击"邮件。"

在"显示名:"字段中输入您的姓名,然后单击"下一步"。

在"电子邮件地址:"字段中输入您的完整 Gmail 电子邮件地址 (username@gmail.com),然后单击"下一步"。

在"接收邮件(POP3, IMAP 或 HTTP)服务器:"字段中输入"pop.gmail.com"。在"发送邮件服务器 (SMTP):"字段中输入"smtp.gmail.com"。

单击"下一步"。

在"帐户名:"字段中输入您的 Gmail 用户名(包括"@gmail.com")。在"密码:"字段中输入您的 Gmail 密码,然后单击"下一步"。

单击"完成"。

突出显示"帐户"下的"pop.gmail.com",并单击"属性"。

单击"高级"标签。

选中"发送邮件 (SMTP)"下"此服务器要求安全连接 (SSL)"旁边的复选框。

在"发送邮件 (SMTP):"字段中输入"465"。

选中"接收邮件 (POP3)"下"此服务器要求安全连接 (SSL)"旁边的复选框。此端口将更改为 995。

*"发送"和"接收"邮件服务器字段的顺序因版本而异。确保您在每一字段中输入了正确信息。

9.如何用Python来发送邮件

SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件、HTML邮件以及带附件的邮件。

Python对SMTP支持有smtplib和email两个模块,email负责构造邮件,smtplib负责发送邮件。推荐教程:/wiki//。

python发邮件中文

转载请注明出处编程代码网 » python发邮件中文(python发送邮件,附件中文命名,怎么破)

资讯

python字符串嵌套(python列表的嵌套该怎么理解)

阅读(10)

本文主要为您介绍python字符串嵌套,内容包括python列表的嵌套该怎么理解,求助python嵌套字典字符串格式化,python用字符串拼接一条语句,然后怎么执行。不对…这里[row[i] for row in matrix] for i in range(4)是一个整体,不然row[i] for

资讯

pythontelnet爆破(如何实现python和telnet通信)

阅读(16)

本文主要为您介绍pythontelnet爆破,内容包括如何实现python和telnet通信,怎样写python脚本控制telnet,python求大神帮助,如何判断是否telnet成功。Windows下开启Telnet服务(详见:与Win7防火墙无缝结合 Telnet功能测试)Windows 2000/XP/2003/V

资讯

pythondecode参数(python的instr.decode在哪个库)

阅读(11)

本文主要为您介绍pythondecode参数,内容包括python怎么使用decode,python怎么使用decode,pythondecode中文编码。问题: Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP"

资讯

python加密狗(python中如何设计一个密码加密器)

阅读(10)

本文主要为您介绍python加密狗,内容包括学了python能破解加密狗吗?,python中如何设计一个密码加密器,Python有什么模块来加密。你好,我自己设计了一个小小的加密器玩。你可以参考一下。这是带有界面的。其中的算法你可以改掉。我是用来把密

资讯

python2.7.6升级(怎样从python2.7.6升级到2.7.12)

阅读(10)

本文主要为您介绍python2.7.6升级,内容包括怎样从python2.7.6升级到2.7.12,怎样把linux的python2.7.6升级到python2.7.12,怎样把linux的python2.7.6升级到python2.7.12。第一步:下载 # wget thon.org/ftp/python/2.7.12/Python-2.7.12.tar.x

资讯

python2.7版本(如何在Windows7上下载Python2.7?)

阅读(10)

本文主要为您介绍python2.7版本,内容包括如何在Windows7上下载Python2.7?,如何下载Wxpython2.7版本的python,64位系统,怎么下载?找不到啊,如何在Windows7安装Python2.7。说明:win7安装python2.7非常简单,只要到官方网站下载然后直接安装即可

资讯

pythonminint(pythonint什么意思)

阅读(10)

本文主要为您介绍pythonminint,内容包括pythonint什么意思,(n:int)>int:在python里是什么意思,python中center怎么用。int在python里是一个类,它是不可变数据类型中的一种,它的一些性质和字符串是一样的,是整型。1. Python int数字类型:整

资讯

pythonnumpy空数组(python怎么输入一个数组矩阵)

阅读(10)

本文主要为您介绍pythonnumpy空数组,内容包括python中数组为空怎么表示,python中数组为空怎么表示,python怎么判断numpy.ndarray是否空。下面是基于python3.4的数组矩阵输入方法:1.import numpy as np2.arr = [1,2,3,4,5,6,7,8

资讯

python字符串嵌套(python列表的嵌套该怎么理解)

阅读(10)

本文主要为您介绍python字符串嵌套,内容包括python列表的嵌套该怎么理解,求助python嵌套字典字符串格式化,python用字符串拼接一条语句,然后怎么执行。不对…这里[row[i] for row in matrix] for i in range(4)是一个整体,不然row[i] for

资讯

pythontelnet爆破(如何实现python和telnet通信)

阅读(16)

本文主要为您介绍pythontelnet爆破,内容包括如何实现python和telnet通信,怎样写python脚本控制telnet,python求大神帮助,如何判断是否telnet成功。Windows下开启Telnet服务(详见:与Win7防火墙无缝结合 Telnet功能测试)Windows 2000/XP/2003/V

资讯

pythondecode参数(python的instr.decode在哪个库)

阅读(11)

本文主要为您介绍pythondecode参数,内容包括python怎么使用decode,python怎么使用decode,pythondecode中文编码。问题: Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP"

资讯

python编译成dll(python有没有办法能够编译成DLL文件呢?)

阅读(13)

本文主要为您介绍python编译成dll,内容包括python程序怎么编译成dll,python程序怎么编译成dll,python有没有办法能够编译成DLL文件。我在工作中就是用python些程序,再用c\c++封装掉 给同事调用的具体的做法是1. python 程序用 py2exe 打包(