1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python发送邮件outlook_通过Python发送Outlook电子邮件?

python发送邮件outlook_通过Python发送Outlook电子邮件?

时间:2022-01-01 19:45:38

相关推荐

python发送邮件outlook_通过Python发送Outlook电子邮件?

I am using Outlook .

What is the best way to send email (through Outlook ) using Python?

解决方案

For a solution that uses outlook see TheoretiCAL's answer below.

Otherwise, use the smtplib that comes with python. Note that this will require your email account allows smtp, which is not necessarily enabled by default.

SERVER = ""

FROM = "yourEmail@"

TO = ["listOfEmails"] # must be a list

SUBJECT = "Subject"

TEXT = "Your Text"

# Prepare actual message

message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\

%s

""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

import smtplib

server = smtplib.SMTP(SERVER)

server.sendmail(FROM, TO, message)

server.quit()

EDIT: this example uses reserved domains like described in RFC2606

SERVER = ""

FROM = "johnDoe@"

TO = ["JaneDoe@"] # must be a list

SUBJECT = "Hello!"

TEXT = "This is a test of emailing through smtp of ."

# Prepare actual message

message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\

%s

""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

import smtplib

server = smtplib.SMTP(SERVER)

server.login("MrDoe", "PASSWORD")

server.sendmail(FROM, TO, message)

server.quit()

For it to actually work with gmail, Mr. Doe will need to go to the options tab in gmail and set it to allow smtp connections.

Note the addition of the login line to authenticate to the remote server. The original version does not include this, an oversight on my part.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。