-
Notifications
You must be signed in to change notification settings - Fork 0
/
smtp.cpp
81 lines (80 loc) · 2.98 KB
/
smtp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "smtp.h"
#include<qDebug>
smtp::smtp(QByteArray username,QByteArray password)
{
if(username.contains("@qq"))
{
this->username = username;
this->password = password;
}
else
qDebug()<<"NOT qq";
}
void smtp::send(QByteArray recvaddr,QString subject,QString content)
{
this->recvaddr = recvaddr;
this->subject = subject;
this->content = content;
QByteArray usernametmp = this->username;
QByteArray recvaddrtmp = this->recvaddr;
clientsocket=new QTcpSocket();
this->clientsocket->connectToHost("smtp.qq.com",25,QTcpSocket::ReadWrite);
this->clientsocket->waitForConnected(1000);
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
this->clientsocket->write("HELO smtp.qq.com\r\n");
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
this->clientsocket->write("AUTH LOGIN\r\n");
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
qDebug()<<"username:"<<username;
this->clientsocket->write(username.toBase64().append("\r\n"));
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
qDebug()<<"password:"<<password;
this->clientsocket->write(password.toBase64().append("\r\n"));
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
this->clientsocket->write(mailfrom.append(usernametmp.append(">\r\n")));
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
//发送邮箱
//qDebug()<<"mail from:"<<mailfrom.append(usernametmp.append(">\r\n"));
this->clientsocket->write(rcptto.append(recvaddrtmp.append(">\r\n")));
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
//接收邮箱
//qDebug()<<"rcp to:"<<rcptto.append(recvaddrtmp.append(">\r\n"));
//data表示开始传输数据
this->clientsocket->write("data\r\n");
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
usernametmp = this->username;
recvaddrtmp = this->recvaddr;
this->clientsocket->write(prefrom.append(usernametmp.append("\r\n")));
this->clientsocket->write(preto.append(recvaddrtmp.append("\r\n")));
this->clientsocket->write(presubject.append(subject.toLocal8Bit().append("\r\n")));
this->clientsocket->write("\r\n");
this->clientsocket->write(content.toLocal8Bit().append("\r\n"));
this->clientsocket->write(".\r\n");
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
this->clientsocket->write("quit\r\n");
this->clientsocket->waitForReadyRead(1000);
recvdata = clientsocket->readAll();
qDebug()<<recvdata;
}
smtp::~smtp()
{
delete this->clientsocket;
}