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
|
envoiMail::envoiMail()
{
prenom = new QLineEdit(this);
nom = new QLineEdit(this);
adresse = new QLineEdit(this);
envoi = new QPushButton(tr("Envoyer"), this);
smtp = new Smtp("noreply.callimarco@gmail.com", "callimarco123", "smtp.gmail.com");
QFormLayout *lay = new QFormLayout;
QVBoxLayout *layPrinc = new QVBoxLayout;
lay->addRow(tr("Prénom: "), prenom);
lay->addRow(tr("Nom: "), nom);
lay->addRow(tr("Adresse Mail: "), adresse);
if(adresse.contains(QRegExp("^[\w|\.]+@[\w]+\.[\w]{2,4}$")))
{
QMessageBox::information(this, "Message envoyé","Message envoyé");
this->close();
}
else
QMessageBox::critical (this, "l'adresse", EntryText + " n'est pas valide !");
return;
layPrinc->addLayout(lay);
layPrinc->addWidget(envoi);
setLayout(layPrinc);
setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/img/ico_32.png"));
connect(envoi, SIGNAL(clicked()), this, SLOT(envoyerMail()));
QWidget::connect(smtp, SIGNAL(status(QString)), this, SLOT(mailEnvoye(QString)));
}
envoiMail::~envoiMail()
{
smtp->deleteLater();
}
void envoiMail::envoyerMail()
{
QString corps = "Voici les informations à propos de la nouvelle demande \nPrénom: " + prenom->text() + "\nNom: " + nom->text() + "\nAdresse mail: " + adresse->text() + genererCode();
smtp->sendMail(information personnelle ,corps);
//QMessageBox::information(this, tr("Mail envoyé"), tr("Votre demande a bien été envoyée, consultez vos mails régulièrement pour le récupérer."));
QFile fic(QCoreApplication::applicationDirPath()+"/infos.txt");
if(fic.open(QIODevice::WriteOnly))
{
QTextStream flux(&fic);
flux << "Attente";
fic.close();
qDebug() << "Fini fichier";
}
//this->close();
}
void envoiMail::mailEnvoye(QString status)
{
if (status == "Message sent")
{
QMessageBox::information(this, "Message envoyé","Message envoyé");
this->close();
}
} |
Partager