I am using Outlook 2003.
What is the best way to send email (through Outlook 2003) using Python?
I am using Outlook 2003.
What is the best way to send email (through Outlook 2003) using Python?
A simple solution for Office 365 is
from O365 import Message
html_template = """
<html>
<head>
<title></title>
</head>
<body>
{}
</body>
</html>
"""
final_html_data = html_template.format(df.to_html(index=False))
o365_auth = ('sender_username@company_email.com','Password')
m = Message(auth=o365_auth)
m.setRecipients('receiver_username@company_email.com')
m.setSubject('Weekly report')
m.setBodyHTML(final)
m.sendMessage()
Here df is a dataframe converted to an html Table, which is being injected into html_template
This is a pretty old question but there is one more solution. The current Outlook SMTP server is (as of 2022):
smtp.office365.com587 (for TLS)Probably the easiest and cleanest solution is to use Red Mail that has these already set:
pip install redmail
Then:
from redmail import outlook
outlook.user_name = "example@hotmail.com"
outlook.password = "<MY PASSWORD>"
outlook.send(
receivers=["you@example.com"],
subject="An example",
text="Hi, this is an example."
)
Red Mail supports all sorts of advanced features:
Links:
Disclaimer: I'm the author
Other than win32, if your company had set up you web outlook, you can also try PYTHON REST API, which is officially made by Microsoft. (https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations)