随笔 - 836  文章 - 1 评论 - 40 阅读 - 102万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

.

.

.参考:https://www.runoob.com/python3/python3-smtp.html

 

复制代码
#encoding=utf-8
'''
Created on 2019年10月11日
@author: sea
'''
import smtplib
from email.mime.text import MIMEText
from email.header import Header
 


def send(From,to,subject,content):
    ''' send(From,to,subject,content) '''
    sendMsg(to,subject,content,From)


def sendTo(to,subject,content):
    '''sendTo(to,subject,content)'''
    sendMsg(to,subject,content)

 
def sendMsg(To,Subject,Content,From='sea@icil.net',Host='192.168.16.253'):
    message = MIMEText(Content, 'plain/html', 'utf-8')
    message['Subject'] = Header(Subject, 'utf-8')
    message['From'] = From    # 发送者
    message['To'] = ''        # 接收者
    for receiver in To: 
        message['To']+=receiver
    try:
        '''if is 3rd email'''
#         smtpObj.connect(mail_host, 25)    # 25 为 SMTP 端口号 mail_host ="smtp.XXX.com"  #设置服务器
#         smtpObj.login(mail_user,mail_pass)   //登录用户名,密码
        smtpObj = smtplib.SMTP(Host,25)
        smtpObj.sendmail(From, To, message.as_string())
        print ("邮件发送成功")
    except smtplib.SMTPException:
        print ("Error: 无法发送邮件")
        
        
        
        
if __name__ == '__main__':
    From = 'SeaSend@sea.net'
    To = ['sealiu@sea.net',"lshan523@163.com"]  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
    Subject = 'Python SMTP 邮件测试  hahhahhaahahahah   toototoootoot'
    Content="'Python 邮件发送测试...'"
    Host='192.168.168.253'
#     send(From, To, Subject, Content)
    sendTo(To, Subject, Content)
    
复制代码

 

posted on   lshan  阅读(226)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示