“smtplib” creates a Simple Mail Transfer ProtocolSMTP) client session object which is used to send emails to any valid email id on the internet. Different websites use different port numbers.
Simple Mail Transfer Protocol (SMTP) is a protocol, which handles sending e-mail and routing e-mail between mail servers.
import smtplib smtpObj = smtplib.SMTP( [host [, port [, local_hostname]]] )
send an email message using the email package alone. You need a combination of both email and smtplib.
Basic steps for sending emails using Python:
To send the mail you use smtpObj to connect to the SMTP server on the local machine and then use the sendmail method along with the message, the from address, and the destination address as parameters (even though the from and to addresses are within the e-mail itself, these aren't always used to route mail).
sendemail(from_addr = 'email@example.com', to_addr_list = ['firstname.lastname@example.org'], cc_addr_list = ['To@todomain.com'], subject = 'Learn Python', message = 'Learning Python Email', login = 'xxxxxxx', password = 'XXXXX')
sendemail(from_addr = 'email@example.com', to_addr_list = ['To@todomain.com'], cc_addr_list = ['To@todomain.com'], subject = 'Learn Python', message = 'Learning Python Email', login = 'xxxxxxx', password = 'XXXXX')