How to send emails if not via IMAP or SMTP?

New to Python here.

In Mid 2022 Microsoft shut down all it’s SMTP and POP servers due to security concerns. The protocols are old and IMAP is more secure they said. I thought I could send email with an attachment using IMAP but after using Gemini AI how to do this, it says IMAP is not intended to do that.

How do I send email these days using Python if I cannot use IMAP or SMTP? Also I will not have a security certificate, I’m on my own for this task.

Thank you.

1 Like

As far as I know you must use SMTP to send emails.
I search of the web also seems to confirm this.
IMAP is only for accessing the mailboxes on a server unless
Microsoft has an extension maybe?

You might find this useful How to send SMTP email for office365 with python using tls/ssl - Stack Overflow

It was undated recently and shows code to use smtp to send emails using office 365.

1 Like

Thanks Barry. Since Microsoft no longer supports SMTP servers I’ll have to ask our IT people to get one from another company.

I’m not a o365 user anymore, but when I was the IT people could turn on and off features.
You might like to ask your IT people if it is possible to enable SMTP for an account you control, maybe not your main account.

See also: O365 · PyPI (which is referred to in @barry-scott’s reply), which includes an example of how to send mail in its description.

Authentication will be harder than using plain SMTP, and likely requires some help from whoever supports your M365 tenant.

Thanks everyone. IT told me of a different SMTP server that was still active (ie. we still paid for it), but I didn’t know about it. So I used that one and got it working.

However smtplib didn’t work as it requires the programmer to create the email headers themselves, which I didn’t know how to do. The program would not get errors but I would not get the email I sent myself either. This I turned into its own function.

So I got it working using from email import utils. This I turned into its own function. This import line will help you search for the page I got the example from.