資源簡介
在網(wǎng)上找了好久Qt實現(xiàn)smtp發(fā)送郵件的簡易版本,一直沒有找到,最終在github上找到別人六七年前寫的開源代碼,經(jīng)過改良能夠在Qt5.11.1上運行,希望那個對大家有用

代碼片段和文件信息
/*
Copyright?(c)?2012?Nicholas?Smith
Permission?is?hereby?granted?free?of?charge?to?any?person?obtaining?a?copy?of?this?software?and?associated?documentation?files?(the?“Software“)?to?deal?in?the?Software?without?restriction?including?without?limitation?the?rights?to?use?copy?modify?merge?publish?distribute?sublicense?and/or?sell?copies?of?the?Software?and?to?permit?persons?to?whom?the?Software?is?furnished?to?do?so?subject?to?the?following?conditions:
The?above?copyright?notice?and?this?permission?notice?shall?be?included?in?all?copies?or?substantial?portions?of?the?Software.
THE?SOFTWARE?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF?ANY?KIND?EXPRESS?OR?IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO?THE?WARRANTIES?OF?MERCHANTABILITY?FITNESS?FOR?A?PARTICULAR?PURPOSE?AND?NONINFRINGEMENT.?IN?NO?EVENT?SHALL?THE?AUTHORS?OR?COPYRIGHT?HOLDERS?BE?LIABLE?FOR?ANY?CLAIM?DAMAGES?OR?OTHER?LIABILITY?WHETHER?IN?AN?ACTION?OF?CONTRACT?TORT?OR?OTHERWISE?ARISING?FROM?OUT?OF?OR?IN?CONNECTION?WITH?THE?SOFTWARE?OR?THE?USE?OR?OTHER?DEALINGS?IN?THE?SOFTWARE.*/
#include?“smtp.h“
Smtp::Smtp(const?QString?&serverName?const?QString?&username?const?QString?&password?const?QString?&from?const?QStringList?&to?const?QString?&subject?const?QString?&body)
{
????server?=?serverName;?//your?server?name
????user?=?username;?//your?SMTP?username
????pass?=?password;?//your?SMTP?password
????user?=?user.toLocal8Bit().tobase64();
????pass?=?pass.toLocal8Bit().tobase64();
????x?=?1;
????int?recipCount?=?0;
????socket?=?new?QTcpSocket(this);
????connect(socket?SIGNAL(readyRead())?this?SLOT(readyRead()));
????connect(socket?SIGNAL(connected())?this?SLOT(connected()?)?);
????connect(socket?SIGNAL(error(QAbstractSocket::SocketError))?this
?????????????SLOT(errorReceived(QAbstractSocket::SocketError)));
????connect(socket?SIGNAL(stateChanged(?QAbstractSocket::SocketState))?this
?????????????SLOT(stateChanged(QAbstractSocket::SocketState)));
????connect(socket?SIGNAL(disconnected())?this
????????????SLOT(disconnected()));
????qDebug()?<“Signals?created“;
????for(recipCount?=?0;?recipCount?????{
????????message.append(“To:?“?+?to.at(recipCount)?+?“\n“);
????}
????message.append(“From:?“?+?from?+?“\n“);
????message.append(“Subject:?“?+?subject?+?“\n“);
????message.append(“Mime-Version:?1.0;\n“);
????message.append(“Content-Type:?text/html;?charset=\“utf8\“;\n“);
????message.append(“Content-Transfer-Encoding:?8bit;\n“);
????message.append(“\n“);
????qDebug()?<“body?is:?“?<????message.append(body);
????message.replace(QString::fromLatin1(?“\n“?)?QString::fromLatin1(?“\r\n“));
????message.replace(QString::fromLatin1(?“\r\n.\r\n“?)?QString::fromLatin1(?“\r\n..\r\n“?)?);
????this->from?=?from;
????rcpt?=?to.at(0);
????recips?=?to;
????state?=?Init;
????socket->connectToHost(server?25);
????if(socket->waitForConnected(30000))
????{
????????qDebug(“connected“);
????}
????t?=?new?QTextStream(?socket?);
}
Smtp::~Smtp()
{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-06-05?14:30??Qt-SMTP-master\
?????文件?????????197??2012-06-05?14:30??Qt-SMTP-master\README
?????目錄???????????0??2018-08-30?13:59??Qt-SMTP-master\example\
?????文件?????????172??2018-08-30?13:59??Qt-SMTP-master\example\main.cpp
?????文件???????15378??2018-08-30?13:04??Qt-SMTP-master\example\Smtptest.pro.user.-1
?????文件?????????392??2018-08-30?13:58??Qt-SMTP-master\example\Smtptest.pro
?????文件???????19350??2018-08-30?13:54??Qt-SMTP-master\example\Smtptest.pro.user
?????文件????????1120??2012-06-05?14:30??Qt-SMTP-master\example\mainwindow.cpp
?????文件?????????345??2012-06-05?14:30??Qt-SMTP-master\example\mainwindow.h
?????文件????????4715??2012-06-05?14:30??Qt-SMTP-master\example\mainwindow.ui
?????文件????????5807??2012-06-05?14:30??Qt-SMTP-master\smtp.cpp
?????文件????????2237??2012-06-05?14:30??Qt-SMTP-master\smtp.h
評論
共有 條評論