【问题标题】:C++ SMTP that allows file attachments允许文件附件的 C++ SMTP
【发布时间】:2011-07-03 22:16:30
【问题描述】:

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

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

【问题讨论】:

  • 还有其他的建议吗?

标签: c++ visual-studio-2010 network-programming smtp email


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    my answer to a previous question 为基础,使用 Visual Studio 付费版本中包含的 Microsoft ATL 类。

    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 类型将取决于附件的类型。

    【讨论】:

    • 虽然很有趣,但这需要 MAPI 吗?我宁愿不需要使用默认的电子邮件程序。
    • 我误读了您链接的帖子,但似乎需要 ATL/非 Express 版本的 Visual Studio。我希望它也可以与 Visual Studio 的快速版本一起使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多