1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <QxtMailMessage>
#include <QxtSmtp>
//---------------------------------------------
void MainDialog::actionTestSendingEmail(){
//*
QString imagePath = "test.jpg";
QString senderEmail = this->ui->lineEditEmailSender->text();
QString passwordSender = this->ui->lineEditPassword->text();
QString receiversString = this->ui->lineEditEmailReceivers->text();
QStringList receivers = receiversString.split(";");
QString emailServor = "smtp.gmail.com";
QxtMailMessage email(senderEmail, senderEmail);
email.setSubject(tr("test webcam recorder"));
email.setBody(tr("a test to check all informations are valid"));
QxtMailAttachment attachment = QxtMailAttachment::fromFile(imagePath);
email.addAttachment(imagePath, attachment);
QxtSmtp smtp;
this->connect(&smtp, SIGNAL(authenticationFailed(QByteArray)), SLOT(authenticationFailed(QByteArray)));
this->connect(&smtp, SIGNAL(connectionFailed(QByteArray)), SLOT(connectionFailed(QByteArray)));
this->connect(&smtp, SIGNAL(mailSent(int)), SLOT(mailSent(int)));
this->connect(&smtp, SIGNAL(mailFailed(int,int,QByteArray)), SLOT(mailFailed(int,int,QByteArray)));
smtp.setUsername(senderEmail.toAscii());
smtp.setPassword(passwordSender.toAscii());
//smtp.connectToSecureHost(emailServor, 465);
//smtp.connectToSecureHost(emailServor, 587);
smtp.connectToSecureHost(emailServor, 587);
//smtp.connectToSecureHost(emailServor);
//if(stmp.
int success = smtp.send(email);
//QMessageBox::critical(this, tr("Erreur"), QString("return:") + success);
///MailSender email(emailServor, senderEmail, receivers, tr("Auto image capture"), tr("Auto image capture"));
///email.setLogin(senderEmail, passwordSender);
///email.setPort(587);
///email.setPort(465);
///email.setSsl(true);
//QStringList attachments(imagePath);
//email.setAttachments(attachments);
//email.setPriority(MailSender::high);
///if(!email.send()){
///QString lastError = email.lastError();
///QMessageBox::critical(this, tr("Erreur"), lastError + tr("\nImpossible d'envoyer l'email. Vérifier votre connexion internet et les informations entrées"));
///}
//*/
}
//---------------------------------------------
void MainDialog::authenticationFailed(const QByteArray & msg){
QString lastError = msg;
QMessageBox::critical(this, tr("Authentication failed"), lastError + tr("\nImpossible d'envoyer l'email. Vérifier votre connexion internet et les informations entrées"));
}
void MainDialog::connectionFailed(const QByteArray & msg){
QString lastError = msg;
QMessageBox::critical(this, tr("Connection failed"), lastError + tr("\nImpossible d'envoyer l'email. Vérifier votre connexion internet et les informations entrées"));
}
void MainDialog::mailSent(int mailID){
QMessageBox::information(this, tr("Email envoyé"), tr("L'email a bien été envoyé"));
}
void MainDialog::mailFailed(int mailID, int errorCode, const QByteArray & msg){
QString lastError = msg;
QMessageBox::critical(this, tr("Email failed"), lastError + tr("\nImpossible d'envoyer l'email. Vérifier votre connexion internet et les informations entrées"));
} |
Partager