I am trying to send email with below code.
import smtplib
from email.mime.text import MIMEText
sender = \'sender@sender.com\'
def mail_me(cont, receiver):
This should work:
msg['From'] = "Your name "
Example below:
import smtplib
from email.mime.text import MIMEText
def send_email(to=['example@example.com'], f_host='example.example.com',
f_port=587, f_user='example@example.com', f_passwd='example-pass',
subject='default subject', message='content message'):
smtpserver = smtplib.SMTP(f_host, f_port)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(f_user, f_passwd) # from email credential
msg = MIMEText(message, 'html')
msg['Subject'] = 'My custom Subject'
msg['From'] = "Your name "
msg['To'] = ','.join(to)
for t in to:
smtpserver.sendmail(f_user, t, msg.as_string()) # you just need to add
this in for loop in your code.
smtpserver.close()
print('Mail is sent successfully!!')
cont = """\
Hi!
How are you?
Here is the link you wanted.
"""
try:
send_email(message=cont)
except:
print('Mail could not be sent')