Rus*_*oom 5 outlook r rdcomclient
我正在尝试使用 从辅助电子邮件地址发送电子邮件RDCOMClient。我听取了如何使用 R RDCOMClient 检索 Outlook 收件箱电子邮件?并尝试用 VBA 编写并翻译,但无法获得正确的命令。
注意:我无法使用,SentOnBehalfOfName因为我没有必要的权限。
以下 VBA 和 Python 代码均成功从辅助收件箱发送电子邮件。
编程语言
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
Run Code Online (Sandbox Code Playgroud)
Python
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()
Run Code Online (Sandbox Code Playgroud)
右
除了猜测我能想到的所有组合之外,我在 R 中尝试过的[["SMTP"]]事情$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()
Run Code Online (Sandbox Code Playgroud)
相关问题:
有想法吗?
资料来源: http ://www.seancarney.ca/2020/10/07/sending-email-from-outlook-in-r/
# Send the message from an alternate account
Email[["sentonbehalfofname"]] = "alternate-sender@test.com"
Run Code Online (Sandbox Code Playgroud)
这家伙成功了。:)
| 归档时间: |
|
| 查看次数: |
2582 次 |
| 最近记录: |