How to open Outlook “New mail message” window from VB.NET

徘徊边缘 提交于 2019-11-29 23:41:09

问题


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).

Any help will be appreciated.


回答1:


If you want specifically want an outlook message and you want more options on what to send (body text, attachments, BCC, etc.):

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



回答2:


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:

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.


Anyway, never open explicitly non-default client (email, browser, etc) - that breaks clients' will and makes them hate you.




回答3:


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


来源:https://stackoverflow.com/questions/4537860/how-to-open-outlook-new-mail-message-window-from-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!