Reputation: 1
I'm working in a company that uses Gmail to send and receive emails from a domain email. To make it clearer, let's say it's [email protected]. Right now my goal is to make a simple script that will send the emails using a list from csv file. The code works fine when I use my personal Gmail email, but the problem starts when I change it to my business account - it seems that the script is ignoring the initialization step because it's not @gmail.com.
Not sure if it's needed, but right now I will be happy to at least run the "yagmail 101" code like the one below. Just for reference, I tried the smtplib as well with same result. The two-factor authentication is on, a 16-char password for Windows mail application was created.
#importing the Yagmail library
import yagmail
try:
#initializing the server connection
yag = yagmail.SMTP(user='[email protected]', password='mypassword')
#sending the email
yag.send(to='[email protected]', subject='Testing Yagmail', contents='Hurray, it worked!')
print("Email sent successfully")
except:
print("Error, email was not sent")
Upvotes: 0
Views: 849
Reputation: 1254
Following the steps here worked if your company has enabled it, otherwise you need to contact administrators at your company: https://support.google.com/accounts/answer/185833?visit_id=638426862839173690-647846903&p=InvalidSecondFactor&rd=1s
Upvotes: 0
Reputation: 9
#importing the Yagmail library
import yagmail
# connect to smtp server.
yag_smtp_connection = yagmail.SMTP( user="[email protected]", password="mypassword",
host='yourSMTPserver')
# email subject
subject = 'Hello'
contents = ['Hello this email send via YAGMAIL']
# send the email
yag_smtp_connection.send('[email protected]', subject, contents)
print("Email send!")
Upvotes: -1