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

Email 如何在VB6中的Microsoft Outlook发件箱中生成电子邮件?,email,vb6,outlook,automation,Email,Vb6,Outlook,Automation,我需要从我的申请中发送电子邮件。但是,我希望通过Microsoft Outlook发送电子邮件,而不是通过SMTP直接发送电子邮件。所以 如何在VB6中的Microsoft Outlook发件箱中生成电子邮件?来自Microsoft的示例 Send a message to your new contact. Dim olMail As Outlook.MailItem Set olMail = olApp.CreateItem(olMailItem) ' Fill out &am

我需要从我的申请中发送电子邮件。但是,我希望通过Microsoft Outlook发送电子邮件,而不是通过SMTP直接发送电子邮件。所以

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

来自Microsoft的示例

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
Microsoft的这篇文章有一些例子

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自动化。这说明了如何从VBA中执行此操作,在VB6中完全相同。“引用”命令位于VB6中的“项目”菜单上,而不是“工具”菜单上,我认为这是唯一的区别。编辑:说明如何在VB6中进行编辑。这是Shoban的功劳,不是我的

我认为MSDN主题也值得一提,因为微软在标题中的拼写错误

使用COM自动化。这说明了如何从VBA中执行此操作,在VB6中完全相同。“引用”命令位于VB6中的“项目”菜单上,而不是“工具”菜单上,我认为这是唯一的区别。编辑:说明如何在VB6中进行编辑。这是Shoban的功劳,不是我的


我认为MSDN主题也值得一提,因为微软在标题中的拼写错误

向Microsoft Outlook X对象库添加项目引用

然后,以一种形式、模块、类或其他任何形式。。。我选择了一个按钮点击事件

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

将项目引用添加到Microsoft Outlook X对象库

然后,以一种形式、模块、类或其他任何形式。。。我选择了一个按钮点击事件

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

请注意,如果您的代码执行了任何可能使Outlook认为您是宏病毒的操作(例如尝试访问通讯簿),用户将看到一个对话框。如果您遇到此问题,请查看Outlook Redemption()。stackoverflow上已回答:请注意,如果您的代码执行了任何可能使Outlook认为您是宏病毒的操作(例如尝试访问通讯簿),用户将看到一个对话框。如果您遇到此问题,请查看Outlook Redemption()。有关stackoverflow的回答: