Folks,
In this blog we will explore how send email to single/multiple email id using python Script.
Python Script: See detailed comments in the Python Script.
# import the smtplib module. import smtplib # from user details from_user_email_id = [provide_your_email_id_here] from_user_email_pwd = [provide_your_email_id_password] # Email Subject email_subject = [provide_your_email_subject] # To user email ids to_user_email_id = [provide_list_of_to_email_ids_comma_seperated] # set up the SMTP server s = smtplib.SMTP(host=[provide_smtp_host_address_here], port=[provide_smtp_port_here]]) s.ehlo() s.starttls() s.ehlo # login the SMTP server using from email id and password. s.login(from_user_email_id, from_user_email_pwd) # Preparing email message header and body. email_header = 'To:' + ", ".join(to_user_email_id) + '\n' + 'From: ' + from_user_email_id + '\n' + 'Subject: ' + email_subject + ' \n' email_body = email_header + [provide_here_email_text] # sending email s.sendmail(from_user_email_id, to_user_email_id, email_body) s.close()
After providing all the required information & save your fileĀ in .py extension. Refer below example.
Execute Script:
Result:
Thanks!
Happy Learning! Your feedback would be appreciated!
Advertisements