如何使表单应用程序通过Outlook发送电子邮件

时间:2013-12-22 21:54:44

标签: vb.net outlook

我试图在StackOverflow和Google上搜索,但没有成功。 我正在创建一个表单应用程序来接收电子邮件正文的一些信息,创建HTML电子邮件并通过Outlook发送。 我看到的任何地方,发现通过GMail发送。但我希望能够在没有用户中断的情况下通过outlook发送。

有人可以帮我一个代码来调用outlook,构建消息并自动发送。还应该能够通过域中的用户名输入一些额外的收件人,它应该自动解析并提取电子邮件,并在通过outlook发送时发送给他们。

邮件内容可能包含姓名,电子邮件地址,电话号码,地址等字段。这应该都位于表格中的HTML电子邮件中。

1 个答案:

答案 0 :(得分:2)

虽然我很困惑你无法找到你想要的东西但我会提供一个答案,因为标题非常清楚,所以它可以简化未来的搜索。

Dim Outlook As New Microsoft.Office.Interop.Outlook.Application
Dim MailItem As Microsoft.Office.Interop.Outlook.MailItem
MailItem = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
With MailItem
    .HTMLBody = "put the body of your email here as a string"
    .Subject = "Subject Line Info"
    'use the below to change from the default email account
    .SentOnBehalfOfName = "YourEmail@yourdomain.you"
    'you can add multiple recipients using .Add()
    .Recipients.Add("Recipient@theirdomain.them")
    'examples of other optional arguments that can be included
    .Attachments.Add([file])
    .Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh
    .Display() 'opens the email for checking prior to sending or use .Send()
End With

根据下面Rahul的评论,您还需要添加对Microsoft Office 14.0对象库的引用。