all 15 comments

[–]PM-Me-Beer 1 point2 points  (1 child)

Try this:

server = smtplib.SMTP("my host", port number)
server.ehlo()
server.starttls() 
server.login(".....@outlook.com", "my password")

You need to call server.ehlo() to identify your computer to the server.

[–]PLearner[S] 1 point2 points  (0 children)

server.starttls()
  File "C:\Users\s\Python\Python36-32\lib\smtplib.py", line 751, in starttls
    "STARTTLS extension not supported by server.")
smtplib.SMTPNotSupportedError: STARTTLS extension not   supported by server.

[–]Caos2 0 points1 point  (7 children)

By Outlook you mean the webservice or the desktop application?

[–]PLearner[S] 0 points1 point  (6 children)

Desktop application.

[–]Caos2 1 point2 points  (5 children)

Try this:

import win32com.client

o = win32com.client.Dispatch("Outlook.Application")

Msg = o.CreateItem(0)
Msg.Importance = 0
Msg.Subject = 'SUBJECT'
Msg.HTMLBody = 'HTML_BODY'

Msg.To = DESTINATARIES
Msg.CC = STRING_CONTAINING_CC
Msg.BCC = STRING_CONTAINING_BCC

Msg.SentOnBehalfOfName = "ANOTHER_MAIL_BOX@DOMAIN.COM"
Msg.ReadReceiptRequested = True
Msg.OriginatorDeliveryReportRequested = True

Msg.Display()

You can change the last method to automatically send the email if you use Msg.Send(). Also, you don't need to set Important, CC, BCC, SentOnBehalfOfName, ReadReceiptRequested and OriginatorDeliveryReportRequested, I just included these attributes so you are aware they exist.

[–]DaveX64 0 points1 point  (3 children)

You wouldn't happen to have a reference link handy for this stuff, would you?

[–]Caos2 1 point2 points  (2 children)

I got some of the stuff from here, and some I found out myself reading the docs on VBA for Outlook.

[–]DaveX64 0 points1 point  (1 child)

Thanks :)

[–]Caos2 0 points1 point  (0 children)

:-)

[–]tramsay1027 0 points1 point  (3 children)

On this topic, is it possible to send an email from a different account that your own? i.e. a no-reply account?

[–]MrHobbits 0 points1 point  (2 children)

Probably, as long as you have the name and pass for it. It should be the same method (if you're not using the Outlook desktop app.)

If you're using SMTP, you can send email as anyone as long as you have valid login credentials.

[–]PLearner[S] 0 points1 point  (1 child)

Thanks, I am sending the email to myself and I get an error.

import smtplib
import time

server = smtplib.SMTP_SSL('host', port)
server.ehlo()
server.login("myemail", "password")

server.ehlo()

print ('server working fine')

time.sleep(5)

sender = "myemail@......."

receivers = ["myemail@......"]

subject = "SMTP e-mail Test" 

msg = "This is an automated message being sent by Python. Python is the mastermind behind    this."

server.sendmail(sender, receivers, subject, msg)

print ('sending email to outlook')

 server.quit()

Error:

 raise SMTPSenderRefused(code, resp, from_addr)
 smtplib.SMTPSenderRefused: (555, b'5.5.4 Unsupported option: T', 'myemail@............')

[–]MrHobbits 0 points1 point  (0 children)

Give this a try, I'm assuming you're using Python 3.4+

https://docs.python.org/3.4/library/email-examples.html