From 7f8d11db2f4009d3379125437e06d96546851058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20T=C5=91k=C3=A9s?= Date: Thu, 30 Oct 2014 22:56:39 +0200 Subject: [PATCH] Set up demo projects. --- demos/{ => demo1}/demo1.cpp | 25 ++++++++++----- demos/demo1/demo1.pro | 29 +++++++++++++++++ demos/demo2/demo2.cpp | 3 +- demos/demo2/demo2.pro | 32 +++++++++++++++++++ demos/demo2/sendemail.cpp | 2 +- demos/demo3.cpp | 63 ------------------------------------- demos/demo3/demo3.pro | 28 +++++++++++++++++ demos/{ => demo4}/demo4.cpp | 25 ++++++++++----- demos/demo4/demo4.pro | 28 +++++++++++++++++ 9 files changed, 155 insertions(+), 80 deletions(-) rename demos/{ => demo1}/demo1.cpp (72%) create mode 100644 demos/demo1/demo1.pro create mode 100644 demos/demo2/demo2.pro delete mode 100644 demos/demo3.cpp create mode 100644 demos/demo3/demo3.pro rename demos/{ => demo4}/demo4.cpp (82%) create mode 100644 demos/demo4/demo4.pro diff --git a/demos/demo1.cpp b/demos/demo1/demo1.cpp similarity index 72% rename from demos/demo1.cpp rename to demos/demo1/demo1.cpp index 5985bae..5531337 100644 --- a/demos/demo1.cpp +++ b/demos/demo1/demo1.cpp @@ -1,11 +1,10 @@ -#include - -#include "../src/SmtpMime" +#include +#include "../../src/SmtpMime" int main(int argc, char *argv[]) { - QApplication a(argc, argv); + QCoreApplication a(argc, argv); // This is a first demo application of the SmtpClient for Qt project @@ -44,9 +43,21 @@ int main(int argc, char *argv[]) // Now we can send the mail - smtp.connectToHost(); - smtp.login(); - smtp.sendMail(message); + if (!smtp.connectToHost()) { + qDebug() << "Failed to connect to host!" << endl; + return -1; + } + + if (!smtp.login()) { + qDebug() << "Failed to login!" << endl; + return -2; + } + + if (!smtp.sendMail(message)) { + 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..668c030 --- /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 -lSMTPEmail + +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..99f9e64 --- /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 -lSMTPEmail + +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..22f65a7 100644 --- a/demos/demo2/sendemail.cpp +++ b/demos/demo2/sendemail.cpp @@ -123,7 +123,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/demo3.cpp b/demos/demo3.cpp deleted file mode 100644 index 3e3e8ec..0000000 --- a/demos/demo3.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2011 - Tőkés Attila - - This file is part of SmtpClient for Qt. - - SmtpClient for Qt is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - SmtpClient for Qt is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. - - See the LICENSE file for more details. -*/ - -#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"); - - // 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 - Demo"); - - // Add some text - MimeText text; - text.setText("Hi!\n This is an email with some attachments."); - 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.setContentType("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(); - -} diff --git a/demos/demo3/demo3.pro b/demos/demo3/demo3.pro new file mode 100644 index 0000000..64cafaa --- /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 -lSMTPEmail + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION diff --git a/demos/demo4.cpp b/demos/demo4/demo4.cpp similarity index 82% rename from demos/demo4.cpp rename to demos/demo4/demo4.cpp index 7749d3c..92b1545 100644 --- a/demos/demo4.cpp +++ b/demos/demo4/demo4.cpp @@ -14,12 +14,13 @@ 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); + QCoreApplication a(argc, argv); // First create the SmtpClient object and set the user and the password. @@ -36,7 +37,6 @@ int main(int argc, char *argv[]) message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); message.setSubject("SmtpClient for Qt - Example 3 - Html email with images"); - // Now we need to create a MimeHtml object for HTML content MimeHtml html; @@ -63,10 +63,21 @@ int main(int argc, char *argv[]) message.addPart(&image2); // Now the email can be sended + if (!smtp.connectToHost()) { + qDebug() << "Failed to connect to host!" << endl; + return -1; + } + + if (!smtp.login()) { + qDebug() << "Failed to login!" << endl; + return -2; + } + + if (!smtp.sendMail(message)) { + qDebug() << "Failed to send mail!" << endl; + return -3; + } - smtp.connectToHost(); - smtp.login(); - smtp.sendMail(message); smtp.quit(); } diff --git a/demos/demo4/demo4.pro b/demos/demo4/demo4.pro new file mode 100644 index 0000000..d1a61f1 --- /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 -lSMTPEmail + +INCLUDEPATH += $$SMTP_LIBRARY_LOCATION +DEPENDPATH += $$SMTP_LIBRARY_LOCATION