C ++ libcurl 使用 GitHub 库发送 SMTP 邮件失败
c++ libcurl sent smtp mail using github library fails
我正在尝试使用此 git 存储库中给出的代码。代码不是我的,我要感谢honeyligo的工作!
不幸的是,我无法正确运行它(我不得不解决一些编译问题,但没什么大不了的(。
将主.cpp设置为
#include <unistd.h>
#include "curlsmtp.h"
int main(){
CurlSmtp* mail = new CurlSmtp(
"MYADDRESS@gmail.com",
"MYPASSWORD",
{ "foo@yahoo.fr" },
{},
{},
{},
"it's a subject",
"hello world you aredfsf",
"smtp.gmail.com",
"465");
mail->send_mail();
sleep(3);
delete mail;
return 0;
}
它不断返回
* Expire in 200 ms for 1 (transfer 0x558a3b95d7e0)
然后在超时后失败。代码大约有 500 行长,注释很好,但我无法弄清楚它为什么会失败。我对 curl 了解不多,但我正在寻找一种自动发送带有 pdf 的邮件的方法,并附在我的高中生身上。我需要实现一个 c++ 解决方案,因为这将是一个更大项目的一部分。
感谢您的帮助!
在从CLI 和使用 libcurl 的 C 应用程序中使用 curl 进行一些测试后,我发现了一个问题:如果您明确使用 smtps (smtps://smtp.gmail.com
(,gmail 只接受 smtp 请求。 由于它在这个curlsmtp lib中硬编码以使用smtp://
,因此您可以修改它(set_curl_option
方法(或直接使用libcurl(这里有一个简单的例子:https://curl.haxx.se/libcurl/c/smtp-mime.html(
此外,您必须在Google帐户中设置2FA并创建应用密码,或者如果没有2FA(https://myaccount.google.com/lesssecureapps(则为安全性较低的应用启用访问权限。
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- C ++ libcurl 使用 GitHub 库发送 SMTP 邮件失败