簡體   English   中英

如何從Outlook和Python中的輔助帳戶發送電子郵件

[英]How to send Email from secondary Account in Outlook and Python

我可以使用第二個電子郵件帳戶,並且希望使用此電子郵件發送自動電子郵件。 我已經嘗試過THISTHIS,但是它仍然使用我的主帳戶而不是第二個帳戶發送郵件。 我在Outlook中使用python。

這是我的代碼:

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()

有關更多信息,請參考以下鏈接:

如何使用RDCOMClient從輔助帳戶發送Outlook電子郵件-轉換現有的VBA代碼?

嘗試使用mail.SentOnBehalfOfName ='2ndaryemail@mail.com'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM