如何从VB.NET打开Outlook"新邮件"窗口

Adn*_*dar 3 .net vb.net email email-client

我有一个场景,用户可以从网格中进行选择(在本地文件夹上上传文件),当用户按"发送"时,应用程序应打开Outlook"新邮件"窗口,将所选文件作为附件(用户选择来自网格).

任何帮助将不胜感激.

aba*_*hev 12

Imports System.Diagnostics

Process.Start(String.Format("mailto:{0}", address))

' set all possible parameters: '

Process.Start(String.Format("mailto:{0}?subject={1}&cc={2}&bcc={3}&body={4}", address, subject, cc, bcc, body))

' also escape spaces: '

Process.Start(String.Format("mailto:{0}?subject=\"{1}\"&cc={2}&bcc={3}&body=\"{4}\"", address, subject, cc, bcc, body))
Run Code Online (Sandbox Code Playgroud)

使用旁边包含新的换行符:

body = body.Replace(Environment.NewLine ,"%0A")
Run Code Online (Sandbox Code Playgroud)

将使用新邮件撰写对话框打开默认电子邮件客户端

如果将Outlook设置为默认客户端,则会将其打开.


无论如何,永远不要打开明确的非默认客户端(电子邮件,浏览器等) - 打破客户的意愿,让他们讨厌你.


Mar*_*evG 6

如果您想特别想要一个Outlook消息,并且您想要更多关于发送内容的选项(正文,附件,BCC等):

Dim Outl As Object
Outl = CreateObject("Outlook.Application")
If Outl IsNot Nothing Then
    Dim omsg As Object
    omsg = Outl.CreateItem(0) '=Outlook.OlItemType.olMailItem'
    'set message properties here...'
    omsg.Display(True) 'will display message to user
End If
Run Code Online (Sandbox Code Playgroud)


小智 6

Dim Outl As Object
Outl = CreateObject("Outlook.Application")
If Outl IsNot Nothing Then
    Dim omsg As Object
    omsg = Outl.CreateItem(0)
    omsg.To = "yusuf@hotmail.com"
    omsg.bcc = "yusuf@gmail.com"
    omsg.subject = "Hello"
    omsg.body = "godmorning"
    omsg.Attachments.Add("c:\HP\opcserver.txt")
    'set message properties here...'
    omsg.Display(True) 'will display message to user
Run Code Online (Sandbox Code Playgroud)