0

我在一家公司工作,该公司使用 Gmail 从域电子邮件中发送和接收电子邮件。为了更清楚,假设它是 firstname@company.com。现在我的目标是制作一个简单的脚本,该脚本将使用 csv 文件中的列表发送电子邮件。当我使用我的个人 Gmail 电子邮件时,代码可以正常工作,但是当我将其更改为我的企业帐户时问题就开始了 - 脚本似乎忽略了初始化步骤,因为它不是 @gmail.com。

不确定是否需要,但现在我很乐意至少运行如下所示的“yagmail 101”代码。仅供参考,我也尝试了 smtplib,结果相同。双重身份验证已打开,为 Windows 邮件应用程序创建了一个 16 字符的密码。

#importing the Yagmail library
import yagmail

try:
    #initializing the server connection
    yag = yagmail.SMTP(user='firstname@company.com', password='mypassword')
    #sending the email
    yag.send(to='recipient_username@gmail.com', subject='Testing Yagmail', contents='Hurray, it worked!')
    print("Email sent successfully")
except:
    print("Error, email was not sent")
4

1 回答 1

-1
#importing the Yagmail library
import yagmail

# connect to smtp server.
yag_smtp_connection = yagmail.SMTP( user="user@company.com", password="mypassword", 
host='yourSMTPserver')

# email subject
subject = 'Hello'

contents = ['Hello this email send via YAGMAIL']

# send the email
yag_smtp_connection.send('to@gmail.com', subject, contents)
print("Email send!")
于 2021-01-05T14:43:53.570 回答