[英]Send email from python
I use the page https://outlook.elbbusinessmail.com/ to send emails from my corporate account and I'm a bit stuck because I can't send the email.我使用页面https://outlook.elbbusinessmail.com/从我的公司帐户发送电子邮件,但我有点卡住了,因为我无法发送 email。 The code I am using is:我正在使用的代码是:
import smtplib
server = smtplib.SMTP(host='outlook.elbbusinessmail.com', port=443)
#Next, log in to the server
server.login("myaccount@company.com", "Password")
#Send the mail
msg = "Hello!" # The /n separates the message from the headers
server.sendmail("myaccount@company.com", "target@company.com", msg)
436/5000 I think the problem is with the server. 436/5000 我认为问题出在服务器上。 I also have configured on my mobile the account from which I send and receive emails and the server that appears to me is exchange.mycompany.com, the port is 443 and it is configured to accept all SSL / TLS certificates.我还在我的手机上配置了我发送和接收电子邮件的帐户,我看到的服务器是 exchange.mycompany.com,端口是 443,它被配置为接受所有 SSL / TLS 证书。
I have tried almost everything, changing the server to the same one that appears on my mobile "exchange.mycompany.com" with port 443 and nothing.我几乎尝试了所有方法,将服务器更改为出现在我的移动“exchange.mycompany.com”上的相同服务器,端口为 443,但什么也没有。
Any ideas?有任何想法吗?
Thank you very much非常感谢
This is an example of how i did it这是我如何做到的一个例子
import smtplib
from email.message import EmailMessage
requirements = {'Baggage Related': [(['pnr'], r"(\d[\- ]?){10}"), (['bag color', 'color'],)], 'Refund': [(['pnr'] ,r"(\d[\- ]?){10}"), (['train name', 'train'],), (['origin', 'from'],), (['destination', 'to'],), (['mobile no','mobile number','mobile','phone'],r"[+]?(\d[\- ]?){10,13}"), (['card no', 'card number', 'card'], r"(\d[\- ]?)+"), (['booking id', 'transaction id', 'referance id', 'referance no'],), (['refund amount', 'amount'],)], 'Special Assistance': [ (['pnr'], r"(\d[\- ]?){10}"), (['destination', 'to'],), (['origin', 'from'],)]}
def send_mail(mail, ticket):
sender = 'support@bookticket.com'
receivers = [mail]
msg = EmailMessage()
msg.set_content(generate_mail(ticket))
msg['Subject'] = "RE: " + ticket['response_list'][0]['content']['subject']
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("USERNAME@gmail.com", "PASSWORD")
server.sendmail(sender, receivers, msg.as_string())
server.quit()
Sorry for the spacing.对不起,间距。 This worked for me If you can add the additional details then it will be more helpfull.这对我有用如果您可以添加其他详细信息,那么它将更有帮助。
import smtplib
email = input('which email do you have?\n').lower()
while(email != 'gmail' and email != 'outlook' and email != 'yahoo'):
email = input('Enter one of the following:\n1.Gmail\n2.Outlook\n3.Yahoo\n\n').lower()
if(email == 'gmail'):
email = 'smtp.gmail.com'
domain = '@gmail.com'
elif(email == 'outlook'):
email = 'smtp-mail.outlook.com'
domain = '@outlook.com'
elif(email == 'yahoo'):
email = 'smtp.mail.yahoo.com'
domain = '@yahoo.com'
conn = smtplib.SMTP(email, 587) # smtp.gmail.com
# smtp-mail.outlook.com
# smtp.mail.yahoo.com
conn.ehlo() # Starting the connection
conn.starttls() # Encrypting the connection
emailid = input('Enter Email address'+'('+domain+')'+'...\n')
emailid+=domain
password = input('Enter your password...\n')
while(True):
try:
conn.login(emailid,password)
print('\nLogged in:)')
break
except smtplib.SMTPAuthenticationError:
print('\n\nIncorrect email or password\n')
print('Is this your email address?\n',emailid,'\n')
yn = input().lower()
if(yn == 'no'):
emailid = input('Re-enter your email address\n')
password = input('Enter password\n')
to=input('Who do you want to send the email to?\n')
subject=input('Subject : ')
text=input('Enter the message\n')
message = 'Subject: '+subject+'\n\n'+text
print('\n\n\n'+message,'\n\nsend?')
send=input()
if send=='yes':
conn.sendmail(emailid,to,message)
print('\nsent!')
else:
print('ok')
#conn.sendmail('FROM','TO','Subject: SUBJECT\n\nMESSAGE')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.