More actions
Created page with "It possible to use the module [https://docs.python.org/3/library/smtplib.html <code>smtplib</code>] to send an Email with python3. <pre> #!/usr/bin/env python3 import smtplib from email.message import EmailMessage to_addr = 'to@example.com' from_addr = 'from@example.com' mail_server = 'mail.example.com' passwd = 'YOUR_MAILBOX_PASSWORD' message = EmailMessage() message["To"] = to_addr message["From"] = from_addr message["Subject"] = 'Sent with Python & Smtpli..." |
No edit summary |
||
Line 1: | Line 1: | ||
It possible to use the module [https://docs.python.org/3/library/smtplib.html <code>smtplib</code>] to send an Email with python3. | It possible to use the module [https://docs.python.org/3/library/smtplib.html <code>smtplib</code>] to send an Email with python3. | ||
< | <syntaxhighlight lang="python" line> | ||
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||
Line 22: | Line 22: | ||
s.sendmail(to_addr, from_addr, message.as_string()) | s.sendmail(to_addr, from_addr, message.as_string()) | ||
s.quit() | s.quit() | ||
</ | </syntaxhighlight> | ||
[[Category: Sending an Email with...]] | [[Category: Sending an Email with...]] |
Latest revision as of 21:40, 28 November 2024
It possible to use the module smtplib
to send an Email with python3.
#!/usr/bin/env python3
import smtplib
from email.message import EmailMessage
to_addr = 'to@example.com'
from_addr = 'from@example.com'
mail_server = 'mail.example.com'
passwd = 'YOUR_MAILBOX_PASSWORD'
message = EmailMessage()
message["To"] = to_addr
message["From"] = from_addr
message["Subject"] = 'Sent with Python & Smtplib'
message.set_payload('This is a test message!')
s = smtplib.SMTP_SSL(mail_server, 465)
s.login(to_addr, passwd)
s.sendmail(to_addr, from_addr, message.as_string())
s.quit()