通过Python从特定的Outlook帐户发送电子邮件? [英] Send Email From Specific Outlook Account Via Python?

查看:667
本文介绍了通过Python从特定的Outlook帐户发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当某些进程完成运行时,我都有一些写给电子邮件实验室用户的代码.这是使用SMTP从Gmail帐户发送的.

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.

但是,我的主管希望从官方部门地址发送邮件,这意味着我已经使用Outlook和MAPI.我已经创建了一个帐户,无论运行该作业的实验室机器如何,我都希望电子邮件源自该帐户.问题是我只能从本地Outlook帐户获取要发送的电子邮件,而并非所有的实验室计算机都具有本地帐户.

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?

推荐答案

按照Eugene的建议,您可以在调用Send之前手动创建一个POP3/SMTP帐户并将其分配给MailItem.SendUsingAccount属性,也可以创建一个动态使用兑换及其

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.

这篇关于通过Python从特定的Outlook帐户发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆