用jwsmtp发送邮件
以下是以163作为例子来做的。
用jwsmtp来发送有两种认证方式,一种叫LOGIN,用户名和密码是分开发送的,一种叫PLAIN,用户名和密码是一次发过去的,163要采用PLAIN来做。
我是在他自带的例子上改的
#include <iostream>
#include "jwsmtp/jwsmtp.h"
using std::cout;
using std::cin;
using std::string;
void Usage() {
cout << "jwSMTP library demo program\n"
"demo2 <email toaddress> <email fromaddress> <smtpserver>\n"
" e.g.\n"
" demo2 recipient@there.com me@server.com mail.server.com\n";
}
int main(int argc, char* argv[])
{
if(argc != 4) {
Usage();
return 0;
}
cout << "jwSMTP library demo program\n\n";
string to(argv[1]);
string from(argv[2]);
string smtpserver(argv[3]);
if(to.length() < 2 || from.length() < 2 || smtpserver.length() < 2) {
Usage();
return 0;
}
char str[2048];
cout << "Please enter the subject of the mail\n";
cin.getline(str, 500);
string subject(str);
strcpy(str, "");
cout << "Please enter the message body end with \".\" on a line by itself\n";
string mailmessage;
while(true) {
cin.getline(str, 2048);
if(!strcmp(str, "."))
break;
mailmessage += str;
mailmessage += "\r\n";
strcpy(str, "");
}
cout << "\nPlease wait sending mail\n";
jwsmtp::mailer mail(to.c_str(), from.c_str(), subject.c_str(), mailmessage.c_str(),
smtpserver.c_str(), jwsmtp::mailer::SMTP_PORT, false);
// using a local file as opposed to a full path.
mail.attach("attach.png");
// Use authentication
mail.username("testuser");
mail.password("secret");
// 注意这里的认证方式
mail.authtype(jwsmtp::mailer::PLAIN);
mail.operator()();
cout << mail.response() << "\n";
return 0;
}
用jwsmtp来发送有两种认证方式,一种叫LOGIN,用户名和密码是分开发送的,一种叫PLAIN,用户名和密码是一次发过去的,163要采用PLAIN来做。
我是在他自带的例子上改的
#include <iostream>
#include "jwsmtp/jwsmtp.h"
using std::cout;
using std::cin;
using std::string;
void Usage() {
cout << "jwSMTP library demo program\n"
"demo2 <email toaddress> <email fromaddress> <smtpserver>\n"
" e.g.\n"
" demo2 recipient@there.com me@server.com mail.server.com\n";
}
int main(int argc, char* argv[])
{
if(argc != 4) {
Usage();
return 0;
}
cout << "jwSMTP library demo program\n\n";
string to(argv[1]);
string from(argv[2]);
string smtpserver(argv[3]);
if(to.length() < 2 || from.length() < 2 || smtpserver.length() < 2) {
Usage();
return 0;
}
char str[2048];
cout << "Please enter the subject of the mail\n";
cin.getline(str, 500);
string subject(str);
strcpy(str, "");
cout << "Please enter the message body end with \".\" on a line by itself\n";
string mailmessage;
while(true) {
cin.getline(str, 2048);
if(!strcmp(str, "."))
break;
mailmessage += str;
mailmessage += "\r\n";
strcpy(str, "");
}
cout << "\nPlease wait sending mail\n";
jwsmtp::mailer mail(to.c_str(), from.c_str(), subject.c_str(), mailmessage.c_str(),
smtpserver.c_str(), jwsmtp::mailer::SMTP_PORT, false);
// using a local file as opposed to a full path.
mail.attach("attach.png");
// Use authentication
mail.username("testuser");
mail.password("secret");
// 注意这里的认证方式
mail.authtype(jwsmtp::mailer::PLAIN);
mail.operator()();
cout << mail.response() << "\n";
return 0;
}
浙公网安备 33010602011771号