Set up demo projects.
This commit is contained in:
parent
9897598885
commit
a42aa8e7ed
@ -1,52 +0,0 @@
|
|||||||
#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 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();
|
|
||||||
|
|
||||||
}
|
|
57
demos/demo1/demo1.cpp
Normal file
57
demos/demo1/demo1.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
|
||||||
|
}
|
29
demos/demo1/demo1.pro
Normal file
29
demos/demo1/demo1.pro
Normal file
@ -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
|
@ -14,12 +14,11 @@
|
|||||||
See the LICENSE file for more details.
|
See the LICENSE file for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include "sendemail.h"
|
#include "sendemail.h"
|
||||||
#include "../../src/SmtpMime"
|
#include "../../src/SmtpMime"
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
32
demos/demo2/demo2.pro
Normal file
32
demos/demo2/demo2.pro
Normal file
@ -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
|
@ -102,20 +102,23 @@ void SendEmail::on_sendEmail_clicked()
|
|||||||
message.addPart(new MimeAttachment(new QFile(ui->attachments->item(i)->text())));
|
message.addPart(new MimeAttachment(new QFile(ui->attachments->item(i)->text())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!smtp.connectToHost())
|
smtp.connectToHost();
|
||||||
|
if (!smtp.waitForReadyConnected())
|
||||||
{
|
{
|
||||||
errorMessage("Connection Failed");
|
errorMessage("Connection Failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth)
|
if (auth)
|
||||||
if (!smtp.login(user, password))
|
smtp.login(user, password);
|
||||||
|
if (!smtp.waitForAuthenticated())
|
||||||
{
|
{
|
||||||
errorMessage("Authentification Failed");
|
errorMessage("Authentification Failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!smtp.sendMail(message))
|
smtp.sendMail(message);
|
||||||
|
if (!smtp.waitForMailSent())
|
||||||
{
|
{
|
||||||
errorMessage("Mail sending failed");
|
errorMessage("Mail sending failed");
|
||||||
return;
|
return;
|
||||||
@ -123,7 +126,7 @@ void SendEmail::on_sendEmail_clicked()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox okMessage (this);
|
QMessageBox okMessage (this);
|
||||||
okMessage.setText("The email was succesfully sended.");
|
okMessage.setText("The email was succesfully sent.");
|
||||||
okMessage.exec();
|
okMessage.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include "../../src/SmtpMime"
|
#include "../../src/SmtpMime"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class SendEmail;
|
class SendEmail;
|
||||||
}
|
}
|
||||||
|
@ -14,26 +14,23 @@
|
|||||||
See the LICENSE file for more details.
|
See the LICENSE file for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtCore>
|
||||||
#include "../src/SmtpMime"
|
|
||||||
|
#include "../../src/SmtpMime"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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.
|
|
||||||
|
|
||||||
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
|
|
||||||
|
|
||||||
smtp.setUser("your_email@gmail.com");
|
|
||||||
smtp.setPassword("your_password");
|
|
||||||
|
|
||||||
// Create a MimeMessage
|
// Create a MimeMessage
|
||||||
|
|
||||||
MimeMessage message;
|
MimeMessage message;
|
||||||
|
|
||||||
message.setSender(new EmailAddress("your_email@gmail.com", "Your Name"));
|
EmailAddress sender("your_email_address@host.com", "Your Name");
|
||||||
message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name"));
|
message.setSender(&sender);
|
||||||
|
|
||||||
|
EmailAddress to("recipient@host.com", "Recipient's Name");
|
||||||
|
message.addRecipient(&to);
|
||||||
|
|
||||||
message.setSubject("SmtpClient for Qt - Demo");
|
message.setSubject("SmtpClient for Qt - Demo");
|
||||||
|
|
||||||
// Add some text
|
// Add some text
|
||||||
@ -51,13 +48,30 @@ int main(int argc, char *argv[])
|
|||||||
message.addPart(&attachment);
|
message.addPart(&attachment);
|
||||||
|
|
||||||
// Add an another 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
|
// Now we can send the mail
|
||||||
|
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
|
||||||
|
|
||||||
smtp.connectToHost();
|
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);
|
smtp.sendMail(message);
|
||||||
|
if (!smtp.waitForMailSent()) {
|
||||||
|
qDebug() << "Failed to send mail!" << endl;
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
smtp.quit();
|
smtp.quit();
|
||||||
|
|
||||||
}
|
}
|
28
demos/demo3/demo3.pro
Normal file
28
demos/demo3/demo3.pro
Normal file
@ -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
|
@ -14,28 +14,25 @@
|
|||||||
See the LICENSE file for more details.
|
See the LICENSE file for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtCore>
|
||||||
#include "../src/SmtpMime"
|
|
||||||
|
#include "../../src/SmtpMime"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
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.
|
|
||||||
|
|
||||||
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
|
|
||||||
|
|
||||||
smtp.setUser("your_email@gmail.com");
|
|
||||||
smtp.setPassword("your_password");
|
|
||||||
|
|
||||||
// Create a MimeMessage
|
// Create a MimeMessage
|
||||||
|
|
||||||
MimeMessage message;
|
MimeMessage message;
|
||||||
|
|
||||||
message.setSender(new EmailAddress("your_email@gmail.com", "Your Name"));
|
EmailAddress sender("your_email_address@host.com", "Your Name");
|
||||||
message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name"));
|
message.setSender(&sender);
|
||||||
message.setSubject("SmtpClient for Qt - Example 3 - Html email with images");
|
|
||||||
|
|
||||||
|
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
|
// Now we need to create a MimeHtml object for HTML content
|
||||||
MimeHtml html;
|
MimeHtml html;
|
||||||
@ -62,11 +59,26 @@ int main(int argc, char *argv[])
|
|||||||
message.addPart(&image1);
|
message.addPart(&image1);
|
||||||
message.addPart(&image2);
|
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.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);
|
smtp.sendMail(message);
|
||||||
|
if (!smtp.waitForMailSent()) {
|
||||||
|
qDebug() << "Failed to send mail!" << endl;
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
smtp.quit();
|
smtp.quit();
|
||||||
|
|
||||||
}
|
}
|
28
demos/demo4/demo4.pro
Normal file
28
demos/demo4/demo4.pro
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user