add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) msg.attach(part) smtp = smtplib.SMTP(server) smtp.sendmail(send_from, send_to, msg.as_string()) smtp.close() 好文要顶 关注我 收藏该文 微信分享 bettermanlu 粉丝- 0 关注- 0 +加关注 0 0 升级...
smtplib可以通过SMTP_SSL 发送,也可以采用普通形式直接初始化,对应的两个参数分别是授权的smtp服务器地址和端口号,因为我 设置的是163的,所以使用smtp.163.com服务器地址,端口号和服务器地址读者可以自己去查。通过生成的 smtp实例,一次调用login,sendemail就可以发送了。最后记得调用quit退出。 发送一封纯文本邮件,看...
'attachment', filename=('utf-8', '', file_path2.split('\\')[-1])) message.attach(attachment) # 发送邮件 try: smtp_obj = smtplib.SMTP('smtp.163.com', 25)
SMTP.login(user, password):登陆到smtp服务器。现在几乎所有的smtp服务器,都必须在验证用户信息合法之后才允许发送邮件。 代码语言:python 代码运行次数:3 运行 AI代码解释 # 通过SMTP登录SMTP服务器smtp=smtplib.SMTP('smtp.qq.com')smtp.set_debuglevel(2)smtp.login('qqnumber@qq.com','password')smtp.quit...
# attachment self.attach_file = self.__get_cfg('attach_file', throw=False) def login_server(self): ''' login server :return: ''' server = smtplib.SMTP_SSL(self.smtp_server, 465) server.set_debuglevel(1) server.login(self.msg_from, self.password) ...
# smtp = smtplib.SMTP("smtp.", 25) # SMTP:普通的邮件发送形式 smtp = smtplib.SMTP_SSL("smtp.", 465) # SMTP_SSL:QQ邮箱的SMTP服务器(端口465或587) smtp.set_debuglevel(1) # 用set_debuglevel(1)就可以打印出和SMTP服务器交互的所有信息 ...
#smtp.set_debuglevel(1) #print (self.sendFrom) smtp.login(self.sendFrom,'xrutyyjbcaae') #print (self.sendTo) smtp.sendmail(self.sendFrom,self.sendTo+self.sendCc,self.msg.as_string()) defmain(): sendMail=SendMail() sendMail.setEmailHeader() ...
msg['To']=msg_totry:#s = smtplib.SMTP_SSL("smtp.163.com",465)s=smtplib.SMTP("smtp.163.com",25)s.login(msg_from,passwd)s.sendmail(msg_from,msg_to,msg.as_string())print("发送成功")exceptsmtplib.SMTPExceptionase:print("发送失败")finally:s.quit() ...
SMTP('smtp.example.com') smtp_obj.login('your_username', 'your_password') # 创建邮件消息体 msg = MIMEText('This is a test email.') msg['Subject'] = 'Test Email' msg['From'] = 'you@example.com' msg['To'] = 'recipient@example.com' # 发送邮件 smtp_obj.send_message(msg) ...
attach(attachment) # 使用smtplib发送邮件 import smtplib smtp_server = smtplib.SMTP('smtp.example.com') smtp_server.login('sender@example.com', 'password') smtp_server.sendmail('sender@example.com', 'recipient@example.com', msg.as_string()) smtp_server.quit() 4.1.2 添加文本、图片、附件及...