如何从 VB.NET 打开 Outlook“新邮件”窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4537860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open Outlook "New mail message" window from VB.NET
提问by Adnan Badar
I've a scenario in which user can make a selection from a grid (having uploaded files on local folder) and when user press "send", application should open Outlook "New mail message" window having selected files as attachments (which user selected from grid).
我有一个场景,用户可以从网格中进行选择(在本地文件夹中上传了文件),当用户按下“发送”时,应用程序应该打开 Outlook“新邮件”窗口,选择文件作为附件(用户选择的从网格)。
Any help will be appreciated.
任何帮助将不胜感激。
回答by abatishchev
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))
Use next to include new line breaks:
使用 next 包含新的换行符:
body = body.Replace(Environment.NewLine ,"%0A")
will open default email client with new message composition dialog.
将打开带有新消息撰写对话框的默认电子邮件客户端。
If Outlook is set as default client, it will be opened.
如果 Outlook 设置为默认客户端,它将被打开。
Anyway, never open explicitly non-default client (email, browser, etc) - that breaks clients' will and makes them hateyou.
无论如何,永远不要打开明确的非默认客户端(电子邮件、浏览器等)——这会破坏客户的意愿并让他们讨厌你。
回答by MarcelDevG
If you want specifically want an outlook message and you want more options on what to send (body text, attachments, BCC, etc.):
如果您特别想要 Outlook 消息,并且想要更多关于发送内容的选项(正文、附件、密件抄送等):
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
回答by yusuf izzettin
Dim Outl As Object
Outl = CreateObject("Outlook.Application")
If Outl IsNot Nothing Then
Dim omsg As Object
omsg = Outl.CreateItem(0)
omsg.To = "[email protected]"
omsg.bcc = "[email protected]"
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

