C++ (Qt)上传到smtp会发送一封空电子邮件
我正在使用Qt,最近我用gmail开发了一个类似的应用程序。现在,我想把这封邮件从outlook发送到gmail编辑:我刚刚尝试使用应用程序密码从outlook发送到outlook,但outlook收件箱中的电子邮件仍然为空结束编辑以下是我的代码:C++ (Qt)上传到smtp会发送一封空电子邮件,c++,qt,email,curl,C++,Qt,Email,Curl,我正在使用Qt,最近我用gmail开发了一个类似的应用程序。现在,我想把这封邮件从outlook发送到gmail编辑:我刚刚尝试使用应用程序密码从outlook发送到outlook,但outlook收件箱中的电子邮件仍然为空结束编辑以下是我的代码: if(file.open(QIODevice::ReadWrite)){ //Writes in the msg.txt QTextStream stream(&file); stream << "From: \
if(file.open(QIODevice::ReadWrite)){ //Writes in the msg.txt
QTextStream stream(&file);
stream << "From: \"Me\" <xxxxxxxxxx@outlook.com>" << endl;
stream << "To: \"Me\" <xxxxxxxxxxxx@gmail.com>" << endl;
stream << "Subject: Subject" << endl;
stream << msg << endl; //msg is just a QString variable
}
QString cmd = "ccurl smtp://smtp-mail.outlook.com:587 -v --mail-from \"xxxxxxxxxxxx@outlook.com\" --mail-rcpt \"xxxxxxxxxxxx@gmail.com\" --ssl -u xxxxxxxxxxxxxx@outlook.com:xxxxxxxxxxxxxx -T \"msg.txt\" -k --anyauth --insecure & pause";
const std::string s = cmd.toStdString();
const char* ccmd = s.c_str();
system(ccmd);
谢谢你的帮助
请注意,不要告诉我使用libcurl,因为在标题的结尾和消息正文的开头之间缺少一行空行。如果没有它,消息的其余部分将被解释为仍然是头的一部分
另外,
endl
在没有正当理由的情况下强制在流中刷新,这会在对文件执行刷新时降低性能。只需使用\n
嗯,你是对的!非常感谢。。。我想知道为什么它能在gmail上工作,我以前认为……也许你在某处发送了一条包含空行的消息?也许。。。。。我想我只是把代码从gmail复制粘贴到outlook。。。不管怎样,它成功了,现在我知道为什么了,我不会再犯那个错误了。
---
Email checked by avast....