【问题标题】:sending emails from gmail with c++ code使用 C++ 代码从 gmail 发送电子邮件
【发布时间】:2011-09-26 23:00:01
【问题描述】:

我对使用 c++ 代码发送电子邮件感兴趣。

到目前为止,我已经尝试在 jwsmtplib 中使用 jwsmtp 库,但没有取得任何真正的成功。有什么建议?以下是我的代码:

//code:
#include <iostream>
#include <jwsmtp/jwsmtp.h>

using std::cout;
using std::endl;

int main(  ) {

std::vector<char> vec;
std::string mess("Foo\nBar");
for(std::string::size_type i = 0; i < mess.length( ); ++i)
  vec.push_back(mess[i]);


jwsmtp::mailer mail("me@gmail.com",              // who the mail is too
                  "sme@gmail.com",              // who the mail is from
                  "There is always room for FooBar",  // subject for the email
                  vec,                                // content of the message
                  "smtp.gmail.com",             // the smtp server to mail to
          465,      //jwsmtp::mailer::SMTP_PORT, // default smtp port (25)
                  false);                             // do not query MX records

mail.username("me@gmail.com");
mail.password("mepassword");


//mail.authtype(jwsmtp::mailer::PLAIN);
mail.send();

return 0;
}

我肯定对其他库或类持开放态度,但我对 OS X 有限制。

我还下载了 POCO 库,正如我在其他线程中看到的那样,但我希望有一个更平坦的学习曲线。如果有人有 POCO 的示例代码,我将不胜感激。

谢谢

【问题讨论】:

  • 您需要使用支持 SSL 的库,因为您只能使用加密连接通过 gmail 发送邮件。遗憾的是,我只知道 Windows 库。
  • 我在 .NET 上使用 C# 遇到了类似的问题,我必须通过端口 587 使用 SSL 才能使其工作。
  • @Rob 我认为 gmail 可以与 STL 一起使用?不?无论如何,我的代码使用端口 465。是 jwsmtp 不能与 SSL 一起使用吗?
  • @ferruccio 但你在哪里使用 jwsmtp 库?
  • 不,我使用的是 .NET Framework 库

标签: c++ email smtp poco


【解决方案1】:

查看VMime 库!

【讨论】:

    猜你喜欢
    • 2022-06-17
    • 2013-10-17
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多