如何从Outlook和Python中的辅助帐户发送电子邮件 [英] How to send Email from secondary Account in Outlook and Python
本文介绍了如何从Outlook和Python中的辅助帐户发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有权使用第二个电子邮件帐户,并且希望与此电子邮件一起发送自动电子邮件。我已经尝试过 THIS 和此,但它仍然使用我的主帐户而不是第二个帐户发送邮件。我正在使用带有Outlook的python。
I have access to a second email account and I want to send automated emails with this email. I already tried THIS and THIS but it still sends mails with my primary account and not with the second one. I am using python with outlook.
这是我的代码:
import os
import csv
def Emailer(message, subject, recipient, anrede, name):
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.GetInspector
header = 'MyHeader'
message = 'MyHTMLMessage'
index = mail.HTMLbody.find('>', mail.HTMLbody.find('<body'))
mail.HTMLbody = "<font size=-1 face='Arial'>" + mail.HTMLbody[:index + 1] + header + message + mail.HTMLbody[index + 1:]
mail.send
with open('Komplette Liste.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=';')
csv_list = list(reader)
row_count = sum(1 for row in csv_list)
for i in range(1,row_count):
unternehmen = str(csv_list[i][0])
mail_address = str(csv_list[i][7])
name = str(csv_list[i][8])
infomail_count = infomail_count + 1
print(mail_address)
Emailer("", "My Subject", "MailTo")
我会感谢你的帮助!
推荐答案
您可以尝试以下代码:
import win32com.client
o = win32com.client.Dispatch("Outlook.Application")
oacctouse = None
for oacc in o.Session.Accounts:
if oacc.SmtpAddress == "myemail@email.com":
oacctouse = oacc
break
#print oacc
#dir(oacc)
#oacc.CLSID
#oacc.GetAddressEntryFromID
Msg = o.CreateItem(0)
if oacctouse:
Msg._oleobj_.Invoke(*(64209, 0, 8, 0, oacctouse)) # Msg.SendUsingAccount = oacctouse
Msg.To="email@email.com"
Msg.HTMLBody = "test env instance #"
Msg.Send()
有关更多信息,请参考以下链接:
For more information, please refer to this link:
如何使用RDCOMClient从辅助帐户发送Outlook电子邮件-翻译现有的VBA代码吗?
这篇关于如何从Outlook和Python中的辅助帐户发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文