如何使用Python中的smtplib从我的常规Outlook帐户发送电子邮件

huangapple go评论66阅读模式
英文:

how to send an email from my regular outlook account using smtplib in python

问题

我正在尝试在Python中使用smtplib从我的常规Outlook(或其他电子邮件服务器)帐户发送电子邮件。但是,我只能找到有关从本地主机发送的帮助。有人可以帮我吗?

我已经尝试了许多在线建议,但似乎都不起作用。

英文:

Im trying to send an email from my regular outlook (or other email server) account in python using the smtplib.However I can only find help on sending from my localhost. Could anyone help me with this?

i have tried many suggestions online but none seem to work.

答案1

得分: 1

以下是您要翻译的代码部分:

import smtplib

username='yonihalberstadt@outlook.com'
password='******'
mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
mailServer.login(username, password)
msg = """Hello!"""
mailServer.sendmail("yonihalberstadt@outlook.com", 
"yonihalberstadt@outlook.com", msg)

希望这能帮助有相同问题的人!

ps: 如果有人可以解释以下代码行对我来说会很棒:

mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()

谢谢!

英文:

hey for anyone who this may help i managed to find a solution to the problem, although i dont fully understand the code.

import smtplib

username='yonihalberstadt@outlook.com'
password='******'
mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
mailServer.login(username, password)
msg = """
Hello!"""
mailServer.sendmail("yonihalberstadt@outlook.com", 
"yonihalberstadt@outlook.com", msg)

hope this helps anyone with the same problem!

ps: if anyone could explain the followings lines of code to me would be great:

mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()

thx!

huangapple
  • 本文由 发表于 2023年2月6日 04:34:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定