资源简介
在网上找了好久Qt实现smtp发送邮件的简易版本,一直没有找到,最终在github上找到别人六七年前写的开源代码,经过改良能够在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 < to.count(); 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: “ << body;
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
相关资源
- Qt 二维码打印
- 线段绘制,并且可以拖动线段绘制
- QT5实现简单的TCP通信例程
- 变电站机器人监控系统界面
- MainWindow.rar
- qt QPainter 绘制跑马灯
- qt activemq mqtt 动态库
- Windows下基于Opencv+Qt的视频聊天客户端
- PyQt5:简单视频播放器
- Qt 使用sendemailapi实现邮件发送
- 关于QT多线程子线程使用信号和槽
- QT 窗口切换
- qt操作office文件的程序
- QTP10破解文件mgn-mqt82
- QT5日历源码
- Linux系统下基于Qt的局域网即时通信系
- QT TableView自定义委托
- 基于QT的简单视频播放器
- UR优傲机器人说明书
- tcpNum.zip
- QT项目code.rar
- qt做一个带有日历和钟表的界面
- 树莓派教程--Qt工程中使用DHT11传感器
- QT实现学生管理系统123783
- qt虚拟键盘26键和数字键
- 基于Qt界面显示的温湿度检测
- qt-opensource-linux-x64-5.7.0.run.txt
- 利用Qt实现的N皇后算法
- beatMouse.zip
- Qt 使用QPainter类在子控件上画图
评论
共有 条评论