【IP地址】

#coding:utf-8

import yagmail as autosend_mail

from loguru import logger
import socket
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
content='ip address'
# 读取文件到列表
# with open("ip.txt","r") as ip_file:
#     array = []
#     content = ip_file.read()
#     print(type(content))
#     content = ip_file.read().splitlines()
#     for line in ip_file:
#         array.append(line)

# 邮件发送
# 发件人信息;(邮箱、密码、服务器)
self_server = autosend_mail.SMTP(user="[email protected]", password="FRHERAUPUK*****", host="smtp.163.com")

email_Name = ["[email protected]"]           # 收件人;
# email_Title = ["demo"]                    # 邮件标题;(非必需)
email_Title = content
email_Content = ip                       # 邮件内容;(非必需)
# email_Annexes = ["ip.txt"]                  # 邮件附件;(非必需)

# self_server.send(to=email_Name, subject=email_Title, contents=email_Content, attachments=email_Annexes)
self_server.send(to=email_Name, subject=email_Title, contents=email_Content)
self_server.close()

logger.info("\n**** Email is sent! ****\n")

猜你喜欢

转载自blog.csdn.net/qq_44824148/article/details/127059918