当您的公司电子邮件托管在Google上时,您可以通过Python脚本使用SMTP协议发送电子邮件。SMTP(Simple Mail Transfer Protocol)是一种用于发送电子邮件的标准协议。
以下是通过Python脚本发送电子邮件的步骤:
import smtplib
from email.mime.text import MIMEText
sender_email = 'your_email@gmail.com'
receiver_email = 'recipient_email@example.com'
subject = '邮件主题'
message = '邮件正文内容'
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = receiver_email
smtp_server = 'smtp.gmail.com'
smtp_port = 587
username = 'your_email@gmail.com'
password = 'your_password'
smtp_obj = smtplib.SMTP(smtp_server, smtp_port)
smtp_obj.starttls()
smtp_obj.login(username, password)
smtp_obj.sendmail(sender_email, receiver_email, msg.as_string())
smtp_obj.quit()
完整的Python脚本如下所示:
import smtplib
from email.mime.text import MIMEText
sender_email = 'your_email@gmail.com'
receiver_email = 'recipient_email@example.com'
subject = '邮件主题'
message = '邮件正文内容'
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = receiver_email
smtp_server = 'smtp.gmail.com'
smtp_port = 587
username = 'your_email@gmail.com'
password = 'your_password'
smtp_obj = smtplib.SMTP(smtp_server, smtp_port)
smtp_obj.starttls()
smtp_obj.login(username, password)
smtp_obj.sendmail(sender_email, receiver_email, msg.as_string())
smtp_obj.quit()
请注意,您需要将your_email@gmail.com
替换为您的发件人电子邮件地址,recipient_email@example.com
替换为收件人电子邮件地址,并提供正确的SMTP服务器、端口、用户名和密码。
推荐的腾讯云相关产品是腾讯云邮件推送(https://cloud.tencent.com/product/sms)和腾讯企业邮(https://cloud.tencent.com/product/exmail),它们提供了稳定可靠的电子邮件服务,适用于企业和个人用户。
领取专属 10元无门槛券
手把手带您无忧上云