本文共 1162 字,大约阅读时间需要 3 分钟。
为了方便,我这儿是自己给自己发的邮件,如果条件允许,你可以用不同的邮件地址来发件和收件。
# Python3import smtplibfrom email.mime.text import MIMETextfrom email.header import Header# 第三方 SMTP 服务mail_host = "smtp.qq.com" # 设置服务器mail_user = "2392863668@qq.com" # 用户名mail_pass = "****************" # 口令sender = '2392863668@qq.com'receivers = ['2392863668@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')message['From'] = Header("Looking", 'utf-8')message['To'] = Header("you", 'utf-8')subject = 'Python SMTP 邮件测试'message['Subject'] = Header(subject, 'utf-8')smtpObj = smtplib.SMTP()smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号smtpObj.login(mail_user, mail_pass)smtpObj.sendmail(sender, receivers, message.as_string())print("邮件发送成功")
# Ruby require 'mail'smtp = { :address => 'smtp.qq.com', :port => 25, :domain => 'qq.com', \ :user_name => '2392863668@qq.com', :password => '****************',\ :enable_starttls_auto => true, :openssl_verify_mode => 'none' }Mail.defaults { delivery_method :smtp, smtp }mail = Mail.new do from '2392863668@qq.com' to '2392863668@qq.com' subject 'Ruby SMTP 邮件测试' body 'Ruby 邮件发送测试...'endmail.deliver!
转载地址:http://yjjqi.baihongyu.com/