0

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 firstname@company.com. 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='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")

1 Answers1

-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!")
  • 2
    Thank you Farid, can you please help the person asking question by explaining what was missing, i.e. why you added the host parameter when you set up SMTP property so that it is more clear for everyone ? – demokritos Jan 05 '21 at 15:06