4

を使用して予備の電子メール アドレスから電子メールを送信しようとしていますRDCOMClientR RDCOMClient を使用して Outlook の受信トレイのメールを取得する方法からアドバイスを受けましたか? VBAで書いて翻訳してみましたが、正しいコマンドを取得できませんでした。

注:SentOnBehalfOfName必要な権限がないため使用できません。

以下の VBA コードと Python コードはどちらも、セカンダリ インボックスから電子メールを正常に送信します。

VBA

Sub SendUsingAccount()

 Dim oAccount As Outlook.Account
 Dim oMail As Outlook.MailItem
 Set oAccount = Application.Session.Accounts.Item(2) 'Index of Mailbox
 Set oMail = Application.CreateItem(olMailItem)
 oMail.Subject = "Sent using MAPI Account"
 oMail.Recipients.Add "email@email.com"
 oMail.Recipients.ResolveAll
 oMail.SendUsingAccount = oAccount
 oMail.Send
End Sub

パイソン

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

R

[["SMTP"]]、などについて考えられるすべての組み合わせを推測することに加えて、Rで試したこと$SmtpAddress

OutApp <- COMCreate("Outlook.Application")
outMail <- OutApp$CreateItem(0)
#1 :No Error, but email sends from primary inbox
oa<-OutApp[["Session"]][["Accounts"]]
second_inbox<-oa$Item(2) 
outMail[["SendUsingAccount"]]=second_inbox
#2: Runs, but sends from primary inbox
outMail[["SendUsingAccount"]]="myemail@email.com"
#From what I read emails need to be accessed with a number,not the name
#3 Runs, but sends from primary inbox (the Python index changes every run)
outMail[["SendUsingAccount"]]="oacc_id_from_Python"

#Rest of reproducible code
outMail[["To"]] = "email@email.com"
outMail[["subject"]] = "Alt Acc"
outMail[["body"]] = "test"
outMail$Send()

関連する質問:

アイデア?

4

1 に答える 1