我需要从我的应用程序发送电子邮件。但是,我不想通过SMTP直接发送电子邮件,而是通过Microsoft Outlook发送邮件。所以...如何在VB6中的Microsoft Outlook发件箱中生成电子邮件消息?
如何在VB6的Microsoft Outlook发件箱中生成电子邮件?
我需要从我的应用程序发送电子邮件。但是,我不想通过SMTP直接发送电子邮件,而是通过Microsoft Outlook发送邮件。所以...如何在VB6中的Microsoft Outlook发件箱中生成电子邮件消息?
如何在VB6的Microsoft Outlook发件箱中生成电子邮件?
这个来自Microsft的support page有例子。
Send a message to your new contact.
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
' Fill out & send message...
olMail.To = olItem.Email1Address
olMail.Subject = "About our meeting..."
olMail.Body = _
"Dear " & olItem.FirstName & ", " & vbCr & vbCr & vbTab & _
"I'll see you in 2 minutes for our meeting!" & vbCr & vbCr & _
"Btw: I've added you to my contact list."
olMail.Send
使用COM自动化。这个KnowledgeBase article解释了如何从VBA做到这一点,它在VB6中完全一样。 References命令位于VB6的Project菜单中,而不是Tools菜单,我认为这是唯一的区别。编辑:This KnowledgeBase article解释如何在VB6中做到这一点。荣誉Shoban为此,upvote his answer不是我的!
我认为MSDN主题Automating Outlook from a Visual Basic applications也值得一提,只是针对微软在标题中的错字!
添加项目引用对Microsoft Outlook X对象库
然后,在窗体,模块,类,或任何...我选择了一个button_click事件。
Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Dim objMail As MailItem
Dim strToAddress As String
Dim strSubject As String
Dim strBody As String
Set objOutlook = New Outlook.Application
Set objMail = Outlook.CreateItem(olMailItem)
strToAddress = "[email protected]"
strSubject = "VB6 test email"
strBody = "This is a test email sent from VB6"
With objMail
.To = strToAddress
.Subject = strSubject
.BodyFormat = olFormatPlain
.Body = strBody
End With
MsgBox "outlook security will now complain as I try to resolve your email addresses against your address book"
objMail.Recipients.ResolveAll
objMail.Save
Set objMail = Nothing
Set objOutlook = Nothing
MsgBox "look in your drafts folder for the new email"
'Thank you, I'm here all week, try the Veal. Good night.
End Sub
请注意,如果你的代码做任何可能使Outlook觉得你是一个宏病毒(如试图访问通讯簿),用户将看到一个对话框呈现。如果您遇到问题,请查看Outlook Redemption(http://www.dimastr.com/redemption)。 – AakashM 2009-06-10 12:48:16
回答采纳率:-2.5%(0)0%(0)0人参与。0人参与。 – 76mel 2009-06-11 09:18:18