[英]Send email from python
我使用頁面https://outlook.elbbusinessmail.com/從我的公司帳戶發送電子郵件,但我有點卡住了,因為我無法發送 email。 我正在使用的代碼是:
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 我認為問題出在服務器上。 我還在我的手機上配置了我發送和接收電子郵件的帳戶,我看到的服務器是 exchange.mycompany.com,端口是 443,它被配置為接受所有 SSL / TLS 證書。
我幾乎嘗試了所有方法,將服務器更改為出現在我的移動“exchange.mycompany.com”上的相同服務器,端口為 443,但什么也沒有。
有任何想法嗎?
非常感謝
這是我如何做到的一個例子
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()
對不起,間距。 這對我有用如果您可以添加其他詳細信息,那么它將更有幫助。
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.