Qt 实现简单邮件发送

本文详细介绍了如何利用Qt库在应用程序中实现简单的邮件发送功能,包括设置SMTP服务器、配置邮件内容和发送邮件的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#ifndef SMTP_H
#define SMTP_H


#include <QtCore>
#include <QCoreApplication>
#include <QObject>

#include <QTcpSocket>
#include <QString>
#include <QTextStream>
#include <QDebug>
#include <QAbstractSocket>
#include <QDateTime>
#include <QDate>
#include <QLocale>
#include <QObject>
#include <QTcpSocket>
 
class Smtp : public QObject
{
	Q_OBJECT
    
	public:
		Smtp(QString smtphost, QString smtpusername, QString smtppass);
		~Smtp();
        bool Send( const QString &to,const QString &subject, const QString &body );
		int linesend;
		QStringList ErrorMSG;
        bool ReadLiner();
        void ErrorCloseAll();

	signals:
		void status( const QString &);
		void SendLine();
    public slots:
        bool PutSendLine();
	private:
		bool isconnect;
		QString smtphost;
		QString smtpusername;
		QString smtppass;
		QString message;
		QString output;
		QString RemoteServerName;
		QString mailstatus;
		QTextStream *t;
		QTcpSocket *smtpsocket;
		QString from;
		QString rcpt;
		QString response;
        QString SendLineAndGrab(QString senddata);
		int Timeout;
		QString encodeBase64( QString xml );
		QString decodeBase64( QString xml );
		int dateswap(QString form, uint unixtime );
		QString TimeStampMail();
    
 
};


#endif

 


#include "smtp.h"

Smtp::Smtp(QString smtphost, QString smtpusername, QString smtppass)
{
	this->smtphost = smtphost;
	this->smtpusername = smtpusername;
	this->smtppass = smtppass;
}

bool Smtp::Send(  const QString &to, const QString &subject, const QString &body )
{
    qDebug()<<"####"<<Q_FUNC_INFO;
    bool res = false;
	int waittime = 5 * 1000;
    this->from = smtpusername;
	rcpt = to;
	ErrorMSG.clear();
	Timeout = waittime;
	linesend = 0;
	isconnect = false;
    

    QString tmp = "=?utf-
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值