简体   繁体   English

如何打开带有附件的默认电子邮件客户端

[英]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 首先,我使用了MAPI,但是即使我已经在“控制面板”中进行了设置,MAPI也无法检测到我的默认电子邮件客户端,它显示了这两个消息框

在此处输入图片说明

在此处输入图片说明

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. HERE'S我在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. 我还使用mail:to协议来调用使用此代码行处理上述协议的默认电子邮件客户端。

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. 我读到一个线程,认为mail:to不再处理附件,但是这一行代码打开了带有主体和主题的默认电子邮件客户端,但是没有附件。 In terms of the filename variable, I already tried every path format, I read that I should use 8.3 path format. 关于filename变量,我已经尝试了每种路径格式,我读到我应该使用8.3路径格式。 But still doesn't work. 但是仍然不起作用。

The last method I used is extending the System.Net.MailMessage.MailMessage() following THIS answer. 我使用的最后一种方法是按照答案扩展System.Net.MailMessage.MailMessage() 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. 这在打开默认电子邮件客户端并将附件附加到邮件方面起作用,但这是不可编辑的,并且默认电子邮件客户端上没有发送按钮,因为这行代码仅生成.eml文件并将其打开。 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. 我正在考虑解析eml文件,但我仍然不知道如何以新的消息形式通过编程方式打开默认电子邮件客户端。 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. 但是,您可以使用System.Net.Mail.SmtpClient和一些简单的自定义UI轻松创建自己的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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