简体   繁体   English

使用客户端的电子邮件应用程序发送附件附件

[英]Send email with attachment using client's email application

I need my locally-installed, thick-client application (Qt / C++) to generate a ready-to-be-sent email message on the client's machine: 我需要在本地安装的胖客户端应用程序(Qt / C ++)在客户端的计算机上生成可立即发送的电子邮件:

  • This message must contain the contents of a relatively small (15K - 200K) binary file. 此消息必须包含相对较小(15K - 200K)二进制文件的内容。
  • Many of my users will be disconnected at the time this message is generated, so it is possible the email will need to sit in the outbox until a later time. 在生成此消息时,我的许多用户都将断开连接,因此电子邮件可能需要在稍后的时间内保留在发件箱中。
  • This application will run on Windows, Mac OS X, and various Linux distros (official support for Ubuntu/Debian and Fedora), and there is no requirement that specific email clients need to be installed. 此应用程序将在Windows,Mac OS X和各种Linux发行版(Ubuntu / Debian和Fedora的官方支持)上运行,并且不要求需要安装特定的电子邮件客户端。

I have already tried: 我已经尝试过了:

  • Opening a mailto: link using QDesktopServices::openUrl() with the attach (or attachment ) parameter. 使用带有attach (或attachment )参数的QDesktopServices::openUrl()打开mailto:链接。 But those parameters are not officially part of the protocol, and some clients (notably Outlook) ignore them. 但这些参数并不是协议的正式部分,有些客户端(尤其是Outlook)会忽略它们。
  • Encoding the file using Base64 and adding it as part of the body parameter of a mailto: link. 使用Base64对文件进行编码,并将其作为mailto: link的body参数的一部分添加。 But the length of the mailto link is truncated by some email clients (again, notably Outlook) so this will not work. 但是mailto链接的长度被一些电子邮件客户端(再次,特别是Outlook)截断,所以这不起作用。

Google Picasa achieves this (at least, on Windows; haven't checked other OS's) when you send pictures from within the application. 当您从应用程序中发送图片时,Google Picasa可以实现此目的(至少在Windows上;未检查其他操作系统)。 It creates a message with the attachments and some pre-filled text. 它会创建一个包含附件和一些预填充文本的消息。 You can then edit the message and send at your convenience. 然后,您可以编辑消息并在方便时发送。 Any ideas how they are doing this? 他们是如何做到这一点的任何想法?

You could create an .eml file and open it which should give you the effect you want as long as there is any email client registered in the system to handle files with this extension. 您可以创建一个.eml文件并打开它,只要在系统中注册了任何电子邮件客户端来处理具有此扩展名的文件,就可以为您提供所需的效果。 I'm sure this is not as universal as the mailto: scheme but if mailto: does not work for you I think this could be the second best option to try. 我确信这不像mailto: scheme那样普遍,但如果mailto:对你不起作用,我认为这可能是第二个尝试的最佳选择。

From http://www.coolutils.com/Formats/EML 来自http://www.coolutils.com/Formats/EML

Since EML files are created to comply with the industry RFC 822 standard, they can be used with most e-mail clients, servers and applications. 由于EML文件的创建符合行业RFC 822标准,因此它们可用于大多数电子邮件客户端,服务器和应用程序。 Besides the Microsoft Outlook Express, EML files can be opened using most e-mail clients, such as Microsoft Outlook, Microsoft Entourage, Mozilla Thunderbird, Apple Mail, and IncrediMail. 除了Microsoft Outlook Express,还可以使用大多数电子邮件客户端打开EML文件,例如Microsoft Outlook,Microsoft Entourage,Mozilla Thunderbird,Apple Mail和IncrediMail。

Side note 边注
When I click 'E-mail' in Picasa I get dialog where I can choose which application (Thunderbird or Google Mail) I want to send email with. 当我点击Picasa中的“电子邮件”时,我会在对话框中选择要发送电子邮件的应用程序(Thunderbird或Google Mail)。 This means Picasa knows specific email client being used to send email and can use custom method, specific to chosen email client, to send email. 这意味着Picasa知道用于发送电子邮件的特定电子邮件客户端,并且可以使用特定于所选电子邮件客户端的自定义方法发送电子邮件。 This is of course just speculation but it might be that Picasa makes user to choose email client because there's no generic way to do what you ask about. 这当然只是猜测,但可能是Picasa让用户选择电子邮件客户端,因为没有通用的方法可以做你所要求的。

I dont think you are using the correct approach ; 我不认为你正在使用正确的方法; use MAPI / C++. 使用MAPI / C ++。 I have done this several times both in Outlook / Thunderbird using MAPI/ C++ . 我使用MAPI / C ++在Outlook / Thunderbird中多次完成此操作。 You can choose the default email client by querying the registry ; 您可以通过查询注册表来选择默认的电子邮件客户端; I think thats what all applications do. 我认为这就是所有应用程序的功能。

Also see the link here http://lists.trolltech.com/qt-interest/2006-02/thread00861-0.html 另请参阅此处的链接http://lists.trolltech.com/qt-interest/2006-02/thread00861-0.html

Some time ago I've began to write a small library for opening the 'default email client' in a platform independent way. 前段时间我开始编写一个小型库,以独立于平台的方式打开“默认电子邮件客户端”。 It still may need some work, but you can use it as a base if you want: https://github.com/picaschaf/qt-email 它仍然可能需要一些工作,但你可以使用它作为基础: https//github.com/picaschaf/qt-email

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

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