简体   繁体   English

如何使用 VBA 在 Office 365 Outlook 中撰写电子邮件?

[英]How to compose email in office 365 outlook using VBA?

I am able to compose email in Desktop Microsoft outlook using the below mentioned code.我可以使用下面提到的代码在桌面 Microsoft Outlook 中撰写电子邮件。 But this code is not working for Microsoft office 365 web outlook .但此代码不适用于Microsoft Office 365 Web Outlook Please provide me Code/Suggestion for composing mail in Microsoft office 365 web outlook.请向我提供在 Microsoft Office 365 Web Outlook 中撰写邮件的代码/建议。

Sub Mail_small_Text_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "Hi there" & vbNewLine & vbNewLine & _
          "This is line 1" & vbNewLine & _
          "This is line 2" & vbNewLine & _
          "This is line 3" & vbNewLine & _
          "This is line 4"

On Error Resume Next
With OutMail
    .To = "ron@debruin.nl"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .Body = strbody
    'You can add a file like this
    '.Attachments.Add ("C:\test.txt")
    .Send   'or use .Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Based on my research, I'm afraid you can't.根据我的研究,恐怕你不能。 Using VBA like yours requires desktop Outlook to be installed.使用像您这样的 VBA 需要安装桌面 Outlook。 There might be a way to send mails via PowerShell.可能有一种方法可以通过 PowerShell 发送邮件。 Just like this as below:就像这样,如下所示:

$olFolderDrafts = 16
$ol = New-Object -comObject Outlook.Application 
$ns = $ol.GetNameSpace("MAPI")

# call the save method yo dave the email in the drafts folder
$mail = $ol.CreateItem(0)
$null = $Mail.Recipients.Add("XXX@YYY.ZZZ")  
$Mail.Subject = "PS1 Script TestMail"  
$Mail.Body = "  Test Mail  "
$Mail.save()
#get it back from drafts and update the body
$drafts = $ns.GetDefaultFolder($olFolderDrafts)
$draft = $drafts.Items | where {$_.subject -eq 'PS1 Script TestMail'}
$draft.body += "`n foo bar"
$draft.save()

Hope that give you new idea for this.希望能给你带来新的想法。

Thanks,谢谢,

Simon西蒙

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Office 365邮件应用程序撰写模式-无法在Outlook桌面客户端中获取电子邮件正文内容 - Office 365 Mail App compose mode - Unable to get email body content in outlook desktop client 如何使用office script excel online在office 365中发送电子邮件 - How to send email in office 365 using office script excel online 如何使用javascript连接到Office 365 Outlook日历 - how to connect to office 365 outlook calender using javascript 如何从邮箱获取Office 365 Outlook的文件夹名称 - How to get office 365 outlook's folders name from a mailbox Office 365 Outlook加载项自定义窗格 - Office 365 Outlook Add-In Custom Pane Outlook外接程序API Office365 - Outlook Add-In API Office365 使用 ActiveXObject 或 Office Javascript API 将电子邮件保存到 Outlook 文件夹? - Save email to outlook folder using ActiveXObject or Office Javascript API? 在 Outlook Office 365 或 Mac 或 PC 上的 Outlook 桌面中自动密件抄送 - Automatically BCC in Outlook Office 365 or Outlook Desktop on Mac or PC Outlook Office 365 AddIn:如何在回复中获取消息文本和传入消息? - Outlook Office 365 AddIn: How to get the message text and the incoming message in a reply? 无法发送电子邮件 nodemailer / office365 - Unable to send email nodemailer / office365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM