当前位置:网站首页>qt send mail program
qt send mail program
2022-08-09 05:53:00 【come on, dude】
通过qt实现发送邮件,使用smtp进行发送.But can't send attachments.(functional research)
First we need to open the mailboxsmtp协议,以163邮箱为例
点击设置按钮
选择pop3选项
Then we need to turn on our computertelnet功能.
首先打开电脑的控制面板
点击程序.
Choose to enable or disable the feature.
将telentCheck this service and click OK.
测试telent是否可用.打开cmd命令窗口,输入telnet
If this window pops up, it means it is available
Turn on these services,And add an authorization code,The authorization code is what you passsmtp登录邮箱的密码.
Preliminary work is ready.
The code part is the passsmtpLog in to your mailbox and send emails.直接看代码.
smtp.h
#ifndef SMTP_H
#define SMTP_H
#include<QByteArray>
#include<QString>
#include<QTcpSocket>
class Smtp
{
public:
Smtp(QByteArray username,QByteArray password);
~Smtp();
void SendData(QByteArray sendIp,QByteArray s_Title,QByteArray s_Content);
QString WaitAndReadData();
private:
QByteArray m_UserName="";
QByteArray m_Password="";
QTcpSocket * m_pSocket=nullptr;
QString m_ReceiverData="";
};
#endif // SMTP_H
smtp.cpp
#include "smtp.h"
#include<QDebug>
Smtp::Smtp(QByteArray username,QByteArray password)
{
if(username.contains("@163"))
{
m_UserName= username;
m_Password = password;
}
else
{
qDebug()<<"Error";
}
}
void Smtp::SendData(QByteArray sendIp, QByteArray s_Title, QByteArray s_Content)
{
m_pSocket=new QTcpSocket();
m_pSocket->connectToHost("smtp.163.com",25,QTcpSocket::ReadWrite); //连接163邮箱
m_pSocket->waitForConnected(1000);
WaitAndReadData();
m_pSocket->write("helo localhost\r\n");
WaitAndReadData();
m_pSocket->write("auth login\r\n");
WaitAndReadData();
m_pSocket->write(m_UserName.toBase64()+"\r\n"); //写入用户名
WaitAndReadData();
m_pSocket->write(m_Password.toBase64()+"\r\n"); //写入密码
WaitAndReadData();
m_pSocket->write("mail from: <"+m_UserName+">\r\n"); //发送的邮箱
WaitAndReadData();
m_pSocket->write("rcpt to: <"+sendIp+">\r\n"); //接收的邮箱
WaitAndReadData();
m_pSocket->write("data\r\n"); //开始写入
WaitAndReadData();
m_pSocket->write("from:<"+m_UserName+">\r\n"); //发送名称
WaitAndReadData();
m_pSocket->write("to:<"+sendIp+">"); //接受名称
WaitAndReadData();
m_pSocket->write("data\r\n");
WaitAndReadData();
m_pSocket->write("Subject:"+s_Title+"\r\n"); //标题
m_pSocket->write("\r\n");
m_pSocket->write(s_Content.append("\r\n")); //内容
m_pSocket->write(".\r\n");
WaitAndReadData();
m_pSocket->write("quit\r\n");
m_pSocket->disconnect();
}
QString Smtp::WaitAndReadData()
{
m_pSocket->waitForReadyRead(1000);
m_ReceiverData = m_pSocket->readAll();
return m_ReceiverData;
}
Smtp::~Smtp()
{
delete m_pSocket;
}
好了,Then test our program.
Smtp smtp("邮箱名称","授权码"); //Use your own email and password //Note the authorization code,Not your password to log in to your email
smtp.SendData("[email protected]","你好","这是一个测试程序");
Email received.
边栏推荐
猜你喜欢

【Word】Word 正文中同时加上下标

Spark源码-任务提交流程-8-DAGScheduler任务切分

RNN-T

2022-08-08:给定一个数组arr,表示从早到晚,依次会出现的导弹的高度。 大炮打导弹的时候,如果一旦大炮定了某个高度去打,那么这个大炮每次打的高度都必须下降一点。 1) 如果只有一个大炮,返回

中断系统结构及中断控制详解

Lock wait timeout exceeded; try restarting transaction 更新数据量范围太大,导致锁表惨案

如何一键进行Win11系统的重装?

数组 冒泡排序

Distributed timing task framework xxl-job source code analysis

滑动窗口篇
随机推荐
获取开发版安全码SHA1时遇到的报错
顺 序 表
打开数字时代的门槛,元宇宙NFT商城开发解决方案
MySQL LIMIT + order by limit n,m 和 limit n的小坑
记一个 nest.js 路由匹配后面所有路径问题
华为鲲鹏生态培训试题
Chapter7、基于图像的光照
八、开发者工具与单元测试
RNN-T
Lock wait timeout exceeded; try restarting transaction 更新数据量范围太大,导致锁表惨案
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
盒子模型中垂直分布的基本内容
【JMeter】jmeter测试 - 上传多个图片/批量上传图片接口 CSV文件参数化方法
STM32Cube学习笔记(delay)
qt发送邮件程序
磁性核壳四氧化三铁颗粒负载金纳米星|磁性Fe3O4-POSS-COOH|超顺磁四氧化三铁聚多巴胺核壳结构纳米粒子
进程和计划任务管理
文件的随意读写
The difference between LDO and DC-DC
数据中台项目前期总结