简体   繁体   中英

How to open default email client with attachment

I'm working on an issue to my project that when I click the button, a default email client should pop out and if there's an attachment, it should be automatically attach to the default email client like this.

在此处输入图片说明

I already tried a lot of methods how to do this. First I used MAPI, but the MAPI cannot detect my Default Email Client even though I already set it in Control Panel, It shows this two message box

在此处输入图片说明

在此处输入图片说明

I already searched the internet about those error but there's no definite or clear answer to me. HERE'S the code I used in MAPI.

I used also the mail:to protocol to call the default email client who's handling to the aforementioned protocol with using this line of codes.

Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()

            Dim filename = Convert.toChar(34) & "C:\USERS\JOSHUA~1.HER\DOWNLO~1\ASDPOR~1.PDF" & Convert.toChar(34)
            Debug.Writeline(filename)
            Dim asd As String = String.Format("mailto:someone@somewhere.com?subject=hello&body=love my body&Attach={0}", filename)
            proc.StartInfo.FileName = asd
            proc.Start()

But still, no luck. I read a thread that the mail:to don't handle attachment anymore, but this line of code opened my default email client with body and subject, but there's no attachment. In terms of the filename variable, I already tried every path format, I read that I should use 8.3 path format. But still doesn't work.

The last method I used is extending the System.Net.MailMessage.MailMessage() following THIS answer. This works in terms of opening the default email client and attaching an attachment to a mail, but this is not editable and there's no send button on the default email client because this line of code just generating an .eml file and opening it. I'm thinking of parsing the eml file but still I don't know how to open the default email client progmatically in a new message form. Here's the photo

在此处输入图片说明

You guys have any idea how to make this possible? Thanks!

I am afraid that this will not be possible to do using some generic method for any mail client. But you can easily create your own solution using System.Net.Mail.SmtpClient and some simple custom UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM