From e6d8578b1d951495b3fe8cea461fb95a412cb5cf Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 6 Sep 2011 18:57:55 +0300 Subject: [PATCH] Demo 3: Sending emails with attachments --- demos/demo3.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 demos/demo3.cpp diff --git a/demos/demo3.cpp b/demos/demo3.cpp new file mode 100644 index 0000000..a33922e --- /dev/null +++ b/demos/demo3.cpp @@ -0,0 +1,54 @@ +#include +#include "../src/SmtpMime" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + // First create the SmtpClient object and set the user and the password. + + SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); + + smtp.setUser("your_email_address@gmail.com"); + smtp.setPassword("your_password"); + + // Create a MimeMessage + + 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"); + + // Add some text + + MimeText text; + + text.setText("Hi,\nThis is a simple email message with some attachments.\n"); + + message.addPart(&text); + + + // Now we create the attachment object + + MimeAttachment attachment (new QFile("image1.jpg")); + + // the file type can be setted. (by default is application/octet-stream) + + attachment.setType("image/jpg"); + + // Now add it to message + + message.addPart(&attachment); + + // Add an another attachment + message.addPart(new MimeAttachment(new QFile("document.pdf"))); + + // Now we can send the mail + + smtp.connectToHost(); + smtp.login(); + smtp.sendMail(message); + smtp.quit(); + +}