How to open default email client with attachment

只愿长相守 提交于 2020-01-04 05:28:18

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/45181148/how-to-open-default-email-client-with-attachment

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