outlook邮件通过python发送,通过Python从特定的Outlook帐户发送电子邮件?

I had some code that was written to email lab users whenever certain processes had finished running. This was sent from a gmail account, using SMTP.

However, my supervisor wants the mail to be sent from an official department address, which means that I have use Outlook and MAPI. I've had an account created which I want the email to originate from regardless of the lab machine the job is being run on. The problem is that I can only get email to send from the local Outlook account, and not all of the lab machines have a local account.

import win32com.client as win32

outlook = win32.Dispatch('outlook.application')

mail = outlook.CreateItem(0)

mail.To = 'user@domain.com'

mail.Subject = 'Message Subject'

mail.body = 'Message text. Message text'

mail.send

Surely there's a way to specify the username/password/server that I want the email to be sent from?

解决方案

As Eugene suggested, you can either manually create a POP3/SMTP account and assign it to the MailItem.SendUsingAccount property prior to calling Send, or you can create a new POP3/SMTP account dynamically using Redemption and its RDOSession.Accounts.AddPOP3Account method.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值