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

时间:2022-07-22
本文章向大家介绍分享一个Qt写的SMTP邮件客户端(库),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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

Qt SMPT客户端支持

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

使用例子

#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