前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >分享一个Qt写的SMTP邮件客户端(库)

分享一个Qt写的SMTP邮件客户端(库)

作者头像
Qt君
发布2020-07-21 10:12:43
3.3K0
发布2020-07-21 10:12:43
举报
文章被收录于专栏:跟Qt君学编程

Qt编写的SMTP客户端(库)。允许应用程序通过SMTP发送电子邮件(有文本,html,附件,内联文件等的MIME)。并支持SSL和SMTP身份验证。

Qt SMPT客户端支持

  • 与SMTP服务器的TCP和SSL连接。
  • SMTP验证(PLAIN和LOGIN方法)。
  • 发送MIME电子邮件(给多个收件人)。
  • 电子邮件中的纯文本和HTML(带有内联文件)内容。
  • 多个附件和内联文件(用于HTML)。
  • 不同的字符集(ascii,utf-8等)和编码方法(7位,8位,base64)。
  • 错误处理。

使用例子

代码语言:javascript
复制
#include <QtGui/QApplication>
#include "../src/SmtpMime"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // This is a first demo application of the SmtpClient for Qt project

    // First we need to create an SmtpClient object
    // We will use the Gmail's smtp server (smtp.gmail.com, port 465, ssl)

    SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);

    // We need to set the username (your email address) and the password
    // for smtp authentification.

    smtp.setUser("your_email_address@gmail.com");
    smtp.setPassword("your_password");

    // Now we create a MimeMessage object. This will be the email.

    MimeMessage message;

    message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name"));
    message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name"));
    message.setSubject("SmtpClient for Qt - Demo");

    // Now add some text to the email.
    // First we create a MimeText object.

    MimeText text;

    text.setText("Hi,\nThis is a simple email message.\n");

    // Now add it to the mail

    message.addPart(&text);

    // Now we can send the mail

    smtp.connectToHost();
    smtp.login();
    smtp.sendMail(message);
    smtp.quit();

}

项目地址

https://github.com/bluetiger9/SmtpClient-for-Qt

下载地址

https://github.com/bluetiger9/SmtpClient-for-Qt/archive/v1.1.zip

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-07-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Qt君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Qt SMPT客户端支持
  • 使用例子
  • 项目地址
  • 下载地址
相关产品与服务
多因子身份认证
多因子身份认证(Multi-factor Authentication Service,MFAS)的目的是建立一个多层次的防御体系,通过结合两种或三种认证因子(基于记忆的/基于持有物的/基于生物特征的认证因子)验证访问者的身份,使系统或资源更加安全。攻击者即使破解单一因子(如口令、人脸),应用的安全依然可以得到保障。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档