C++允许文件附件的 SMTP

发布于 2024-10-19 01:04:49 字数 321 浏览 1 评论 0原文

我希望创建一个允许添加文件附件的 SMTP,但是我发现很难找到教程。我发现了一件很接近的事情,那就是 https://stackoverflow.com/questions/58210/c-smtp-example 但是,由于使用了包含文件,因此在 VS2005/2010 中无法编译。

我想推出自己的库,而不是适应某些库,例如 Curl 或 Boost。有没有人对如何做到这一点有任何建议,或者一些带有良好文档的小示例代码可以在 Visual Studio 中编译?

I am looking to create an SMTP that allows for file attachments, however, I am finding it difficult to locate a tutorial. I have found one close thing, which is https://stackoverflow.com/questions/58210/c-smtp-example , however, this fails to compile in VS2005/2010 because of the include files that are used.

I would like to roll my own and not adapt to some library such as Curl or Boost. Does anyone have any suggestions on how to do this, or some small sample code with good documentation that will compile in Visual Studio?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若无相欠,怎会相见 2024-10-26 01:04:49

基于我对上一个问题的回答,使用Microsoft ATL 类包含在 Visual Studio 的付费版本中。

CSMTPConnection smtp;
if (!smtp.Connect(m_strEmailServer)) 
    return false; 
// start generating the email message; remember to call CoInitialize somewhere in the app before this 
CMimeMessage msg; 
msg.SetSubject(m_strSubject); 
msg.SetSender(m_strSender); 
// repeat the following as necessary 
msg.AddRecipient(strSingleRecipient); 
msg.AddText(m_strBody); 

// add an attachment
msg.AttachFile(m_strAttachmentPath, m_strAttachmentName, _T("application/octet-stream"));

if (!smtp.SendMessage(msg)) 
    return false; 
return true; 

AttachFile 调用中提供的 MIME 类型取决于附件的类型。

Building on my answer to a previous question, using the Microsoft ATL classes which are included in the paid versions of Visual Studio.

CSMTPConnection smtp;
if (!smtp.Connect(m_strEmailServer)) 
    return false; 
// start generating the email message; remember to call CoInitialize somewhere in the app before this 
CMimeMessage msg; 
msg.SetSubject(m_strSubject); 
msg.SetSender(m_strSender); 
// repeat the following as necessary 
msg.AddRecipient(strSingleRecipient); 
msg.AddText(m_strBody); 

// add an attachment
msg.AttachFile(m_strAttachmentPath, m_strAttachmentName, _T("application/octet-stream"));

if (!smtp.SendMessage(msg)) 
    return false; 
return true; 

The MIME type supplied in the AttachFile call will depend on the type of attachment.

生生漫 2024-10-26 01:04:49

有几种方法可以制作附件。您可以使用 UUEncoded 或 MIME 格式。如果您想自己动手,UUEncoded 会简单得多。

There are a couple of ways to do attachments. You can use UUEncoded or MIME formatting. The UUEncoded is much simpler if you want to roll your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文