如何在VB6中的Microsoft Outlook发件箱中生成电子邮件?

时间:2009-06-10 11:56:19

标签: email vb6 outlook automation

我需要从我的应用程序发送电子邮件。但是,我不想通过SMTP直接发送电子邮件,而是通过Microsoft Outlook发送它。所以......

如何在VB6中的Microsoft Outlook发件箱中生成电子邮件?

3 个答案:

答案 0 :(得分:2)

Microsoft的support page有例子。

答案 1 :(得分:2)

使用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也值得一提,只是因为微软在标题中输入错字!

答案 2 :(得分:0)

将项目引用添加到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 = "me@mydomain.com"
  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