iT邦幫忙

1

python寄信問題(已解決)

ddx 2022-01-17 17:47:513212 瀏覽

我現在想要用python寄信
但是我找不到可以用gmail寄信到outlook上
或是不用安裝outlook就可以直接寄信到outlook上
有什麼方法可以解決?
我不想在每台主機上裝outlook
這是我的語法....

#準備訊息物件設定
#載入模組
def email(title,body):
    import email.message
    #建立訊息物件
    msg=email.message.EmailMessage()
    #利用物件建立基本設定
    
    
    msg["From"]="outlook.com"
    msg["To"]="outlook.com"
    msg["Subject"]=title
    
    #寄送郵件主要內容
    #msg.set_content("測試郵件純文字內容") #純文字信件內容
    msg.add_alternative(body,subtype="html") #HTML信件內容
    
    acc="@gmail.com"
    password="password"
    
    #連線到SMTP Sevver
    import smtplib
    #可以從網路上找到主機名稱和連線埠
    server=smtplib.SMTP_SSL("smtp.gmail.com",465) #建立gmail連驗
    server.login(acc,password)
    server.send_message(msg)
    server.close() #發送完成後關閉連線

我找到囉
以下是outlook對outlook 且不用安裝

def send_mail(recipient, subject, message):
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    username = "xx"
    password = "xx"
    
    msg = MIMEMultipart()
    msg['From'] = username
    msg['To'] = recipient
    msg['Subject'] = subject
    msg.attach(MIMEText(message))

    mailServer = smtplib.SMTP('smtp-mail.outlook.com', 587)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(username, password)
    mailServer.sendmail(username, recipient, msg.as_string())
    mailServer.close()



send_mail('收件人', 'test', 'May the force be with you.')
用python打Gmail API不行嗎?
https://developers.google.com/gmail/api
lulu_meat iT邦研究生 5 級 ‧ 2022-01-17 17:51:51 檢舉
可是outlook不是有網頁版嗎?
harrytsai iT邦新手 1 級 ‧ 2022-01-17 17:59:20 檢舉
寄信不是都靠內建的發信軟體如:Exim
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答