diff --git a/demos/demo1.cpp b/demos/demo1.cpp deleted file mode 100644 index 5985bae..0000000 --- a/demos/demo1.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -#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 password - // for smtp authentification. - - smtp.setUser("your_email_address@gmail.com"); - smtp.setPassword("your_password"); - - // Now we create a MimeMessage object. This is 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(); - -} diff --git a/demos/demo1/demo1.cpp b/demos/demo1/demo1.cpp new file mode 100644 index 0000000..7e97e16 --- /dev/null +++ b/demos/demo1/demo1.cpp @@ -0,0 +1,57 @@ +#include + +#include "../../src/SmtpMime" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + // This is a first demo application of the SmtpClient for Qt project + + // Now we create a MimeMessage object. This is the email. + + MimeMessage message; + + EmailAddress sender("your_email_address@host.com", "Your Name"); + message.setSender(&sender); + + EmailAddress to("recipient@host.com", "Recipient's Name"); + message.addRecipient(&to); + + 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 + SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); + + smtp.connectToHost(); + if (!smtp.waitForReadyConnected()) { + qDebug() << "Failed to connect to host!" << endl; + return -1; + } + + smtp.login("your_email_address@host.com", "your_password"); + if (!smtp.waitForAuthenticated()) { + qDebug() << "Failed to login!" << endl; + return -2; + } + + smtp.sendMail(message); + if (!smtp.waitForMailSent()) { + qDebug() << "Failed to send mail!" << endl; + return -3; + } + + smtp.quit(); + +} diff --git a/demos/demo1/demo1.pro b/demos/demo1/demo1.pro new file mode 100644 index 0000000..588da46 --- /dev/null +++ b/demos/demo1/demo1.pro @@ -0,0 +1,29 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-10-30T22:19:03 +# +#------------------------------------------------- + +QT += core + +QT -= gui + +TARGET = demo1 +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += \ + demo1.cpp + +# Location of SMTP Library +SMTP_LIBRARY_LOCATION = $$PWD/../../../build/SMTPEmail-Desktop-Debug + +win32:CONFIG(release, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/release/ -lSMTPEmail +else:win32:CONFIG(debug, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/debug/ -lSMTPEmail +else:unix: LIBS += -L$$SMTP_LIBRARY_LOCATION -lSmtpMime + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION diff --git a/demos/demo2/demo2.cpp b/demos/demo2/demo2.cpp index 75893fd..673086a 100644 --- a/demos/demo2/demo2.cpp +++ b/demos/demo2/demo2.cpp @@ -14,12 +14,11 @@ See the LICENSE file for more details. */ -#include +#include #include "sendemail.h" #include "../../src/SmtpMime" - #include using namespace std; diff --git a/demos/demo2/demo2.pro b/demos/demo2/demo2.pro new file mode 100644 index 0000000..056bbe1 --- /dev/null +++ b/demos/demo2/demo2.pro @@ -0,0 +1,32 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-10-30T22:48:32 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = demo2 +TEMPLATE = app + +SOURCES += \ + demo2.cpp \ + sendemail.cpp + +# Location of SMTP Library +SMTP_LIBRARY_LOCATION = $$PWD/../../../build/SMTPEmail-Desktop-Debug + +win32:CONFIG(release, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/release/ -lSMTPEmail +else:win32:CONFIG(debug, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/debug/ -lSMTPEmail +else:unix: LIBS += -L$$SMTP_LIBRARY_LOCATION -lSmtpMime + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION + +HEADERS += \ + sendemail.h + +FORMS += \ + sendemail.ui diff --git a/demos/demo2/sendemail.cpp b/demos/demo2/sendemail.cpp index 6a0bcd1..840a04d 100644 --- a/demos/demo2/sendemail.cpp +++ b/demos/demo2/sendemail.cpp @@ -102,20 +102,23 @@ void SendEmail::on_sendEmail_clicked() message.addPart(new MimeAttachment(new QFile(ui->attachments->item(i)->text()))); } - if (!smtp.connectToHost()) + smtp.connectToHost(); + if (!smtp.waitForReadyConnected()) { errorMessage("Connection Failed"); return; } if (auth) - if (!smtp.login(user, password)) + smtp.login(user, password); + if (!smtp.waitForAuthenticated()) { errorMessage("Authentification Failed"); return; } - if (!smtp.sendMail(message)) + smtp.sendMail(message); + if (!smtp.waitForMailSent()) { errorMessage("Mail sending failed"); return; @@ -123,7 +126,7 @@ void SendEmail::on_sendEmail_clicked() else { QMessageBox okMessage (this); - okMessage.setText("The email was succesfully sended."); + okMessage.setText("The email was succesfully sent."); okMessage.exec(); } diff --git a/demos/demo2/sendemail.h b/demos/demo2/sendemail.h index 99f9603..585e062 100644 --- a/demos/demo2/sendemail.h +++ b/demos/demo2/sendemail.h @@ -21,8 +21,6 @@ #include "../../src/SmtpMime" - - namespace Ui { class SendEmail; } diff --git a/demos/demo3.cpp b/demos/demo3/demo3.cpp similarity index 61% rename from demos/demo3.cpp rename to demos/demo3/demo3.cpp index 3e3e8ec..1c11a63 100644 --- a/demos/demo3.cpp +++ b/demos/demo3/demo3.cpp @@ -14,26 +14,23 @@ See the LICENSE file for more details. */ -#include -#include "../src/SmtpMime" +#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@gmail.com"); - smtp.setPassword("your_password"); + QCoreApplication a(argc, argv); // Create a MimeMessage - MimeMessage message; - message.setSender(new EmailAddress("your_email@gmail.com", "Your Name")); - message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); + EmailAddress sender("your_email_address@host.com", "Your Name"); + message.setSender(&sender); + + EmailAddress to("recipient@host.com", "Recipient's Name"); + message.addRecipient(&to); + message.setSubject("SmtpClient for Qt - Demo"); // Add some text @@ -51,13 +48,30 @@ int main(int argc, char *argv[]) message.addPart(&attachment); // Add an another attachment - message.addPart(new MimeAttachment(new QFile("document.pdf"))); + MimeAttachment document(new QFile("document.pdf")); + message.addPart(&document); // Now we can send the mail + SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); smtp.connectToHost(); - smtp.login(); + if (!smtp.waitForReadyConnected()) { + qDebug() << "Failed to connect to host!" << endl; + return -1; + } + + smtp.login("your_email_address@host.com", "your_password"); + if (!smtp.waitForAuthenticated()) { + qDebug() << "Failed to login!" << endl; + return -2; + } + smtp.sendMail(message); + if (!smtp.waitForMailSent()) { + qDebug() << "Failed to send mail!" << endl; + return -3; + } + smtp.quit(); } diff --git a/demos/demo3/demo3.pro b/demos/demo3/demo3.pro new file mode 100644 index 0000000..23b6bb1 --- /dev/null +++ b/demos/demo3/demo3.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-10-30T22:20:42 +# +#------------------------------------------------- + +QT += core + +QT -= gui + +TARGET = demo3 +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += \ + demo3.cpp + +# Location of SMTP Library +SMTP_LIBRARY_LOCATION = $$PWD/../../../build/SMTPEmail-Desktop-Debug + +win32:CONFIG(release, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/release/ -lSMTPEmail +else:win32:CONFIG(debug, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/debug/ -lSMTPEmail +else:unix: LIBS += -L$$SMTP_LIBRARY_LOCATION -lSmtpMime + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION diff --git a/demos/demo4.cpp b/demos/demo4/demo4.cpp similarity index 68% rename from demos/demo4.cpp rename to demos/demo4/demo4.cpp index 7749d3c..bdae2f8 100644 --- a/demos/demo4.cpp +++ b/demos/demo4/demo4.cpp @@ -14,28 +14,25 @@ See the LICENSE file for more details. */ -#include -#include "../src/SmtpMime" +#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@gmail.com"); - smtp.setPassword("your_password"); + QCoreApplication a(argc, argv); // Create a MimeMessage MimeMessage message; - message.setSender(new EmailAddress("your_email@gmail.com", "Your Name")); - message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); - message.setSubject("SmtpClient for Qt - Example 3 - Html email with images"); + EmailAddress sender("your_email_address@host.com", "Your Name"); + message.setSender(&sender); + EmailAddress to("recipient@host.com", "Recipient's Name"); + message.addRecipient(&to); + + message.setSubject("SmtpClient for Qt - Example 3 - Html email with images"); // Now we need to create a MimeHtml object for HTML content MimeHtml html; @@ -62,11 +59,26 @@ int main(int argc, char *argv[]) message.addPart(&image1); message.addPart(&image2); - // Now the email can be sended + // Now we can send the mail + SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); smtp.connectToHost(); - smtp.login(); + if (!smtp.waitForReadyConnected()) { + qDebug() << "Failed to connect to host!" << endl; + return -1; + } + + smtp.login("your_email_address@host.com", "your_password"); + if (!smtp.waitForAuthenticated()) { + qDebug() << "Failed to login!" << endl; + return -2; + } + smtp.sendMail(message); + if (!smtp.waitForMailSent()) { + qDebug() << "Failed to send mail!" << endl; + return -3; + } smtp.quit(); } diff --git a/demos/demo4/demo4.pro b/demos/demo4/demo4.pro new file mode 100644 index 0000000..111cc7b --- /dev/null +++ b/demos/demo4/demo4.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-10-30T22:20:54 +# +#------------------------------------------------- + +QT += core + +QT -= gui + +TARGET = demo4 +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += \ + demo4.cpp + +# Location of SMTP Library +SMTP_LIBRARY_LOCATION = $$PWD/../../../build/SMTPEmail-Desktop-Debug + +win32:CONFIG(release, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/release/ -lSMTPEmail +else:win32:CONFIG(debug, debug|release): LIBS += -L$$SMTP_LIBRARY_LOCATION/debug/ -lSMTPEmail +else:unix: LIBS += -L$$SMTP_LIBRARY_LOCATION -lSmtpMime + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION