I read a list of emails in a txt file and sent it from my smtp server.
I am using the same email address for From: and To: which is example@email.com
So, all emails in txt file are: example@email.com
I can receive all the emails from my txt file. My problem is the following:
The subject field is blank and the field To: looks like e,x,a,m,p,l,e@,e,m,a,i,l,.,c,o,m instead of example@email.com
What I am doing wrong?
This is my python code.
import smtplib
def send_email(TOADDRS):
FROMADDR = "example@email.com"
LOGIN = FROMADDR
PASSWORD = "password"
SUBJECT = "Welcome to Stack Overflow"
server = smtplib.SMTP('smtp.example.com',587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
msg += """ This a test \r\n"""
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
if name == "main":
f= open("email.txt","r")
linea=f.readline()
while linea !="":
send_email(linea)
linea = f.readline()
f.close()