2012-12-21 79 views
4

我正在使用以下VBS脚本发送电子邮件,并且工作正常,但是图像作为附件发送。我宁愿将图像嵌入到电子邮件中。我明白我必须在电子邮件的HTML正文中引用附件,但我正在努力做到这一点。使用VBS发送带有嵌入式图像的Outlook电子邮件

有什么建议吗?

Dim ToAddress 
Dim FromAddress 
Dim MessageSubject 
Dim MyTime 
Dim MessageBody 
Dim MessageAttachment 
Dim ol, ns, newMail 
MyTime = Now 

ToAddress = "[email protected]" 
MessageSubject = "Auto Stats " & MyTime 
MessageBody = "Stats Attached" & vbCrLf & "Produced at " & MyTime 
MessageAttachment = "P:\stats.png" 
Set ol = WScript.CreateObject("Outlook.Application") 
Set ns = ol.getNamespace("MAPI") 
Set newMail = ol.CreateItem(olMailItem) 
newMail.Subject = MessageSubject 
newMail.Body = MessageBody 
newMail.RecipIents.Add(ToAddress) 
newMail.Attachments.Add(MessageAttachment) 
newMail.Send 

回答

6

使用下面

Const PR_ATTACH_MIME_TAG = "http://schemas.microsoft.com/mapi/proptag/0x370E001E" 
Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E" 
Const PR_ATTACHMENT_HIDDEN = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B" 


Sub testing2() 
Dim ToAddress 
Dim FromAddress 
Dim MessageSubject 
Dim MyTime 
Dim MessageBody 
Dim MessageAttachment 
Dim ol, ns, newMail 
Dim realAttachment 
MyTime = Now 

ToAddress = "[email protected]" 
MessageSubject = "Auto Stats " & MyTime 
MessageBody = "Stats Attached" & vbCrLf & "Produced at " & MyTime 
MessageAttachment = "C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg" 
Set ns = Outlook.GetNamespace("MAPI") 
Set newMail = Outlook.CreateItem(olMailItem) 
newMail.Subject = MessageSubject 
newMail.Body = MessageBody 
newMail.Recipients.Add (ToAddress) 
Set realAttachment = newMail.Attachments.Add(MessageAttachment) 
Set oPA = realAttachment.PropertyAccessor 
oPA.SetProperty PR_ATTACH_MIME_TAG, "image/jpeg" 
oPA.SetProperty PR_ATTACH_CONTENT_ID, "myident" 'change myident for another other image 
newMail.HTMLBody = newMail.HTMLBody & "<IMG align=baseline border=0 hspace=0 src=cid:myident>" 'need to match the "myident" above 
newMail.Send 
End Sub 

代码希望它可以帮助

相关问题