[英]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.