MimeMessage * MimeMessageBuilder::build(std::vector<Subscriber> &subscribers, QString &name, QDateTime &dateTime, std::vector<QString> &dataNames, std::vector<double> &values, std::vector<QString> &units, std::vector<double> &mins, std::vector<double> &maxs) { if (subscribers.size() > 0) { MimeMessage *message = new MimeMessage(); message->setSender(new EmailAddress(*senderAddress, *senderField)); message->setSubject(*messageTopic); std::vector<Subscriber>::iterator i; for (i = subscribers.begin(); i != subscribers.end(); ++i) { switch ((*i).notification) { case Mail: case Both: message->addRecipient(new EmailAddress((*i).mail, (*i).identifier), MimeMessage::Bcc); default: continue; } } // Adds additional information QString content(*body); content.replace(QRegExp("\\$\\{OBJECT\\}"), name); content.replace(QRegExp("\\$\\{TIME\\}"), dateTime.toString("hh:mm:ss dd.MM.yyyy")); QString details; for (int i = 0; i < values.size(); i++) { details.append(QString("<tr id='m_highlight'>")); details.append(QString("<td id='m_content'>" + dataNames[i] + "</td>")); details.append(QString("<td id='m_content'>" + QString::number(values[i]) + units[i] + "</td>")); details.append(QString("<td id='m_content'><" + QString::number(mins[i]) + "; " + QString::number(maxs[i]) + "></td>")); details.append(QString("</tr>")); } content.replace(QRegExp("\\$\\{DETAILS\\}"), details); MimeHtml *html = new MimeHtml(); html->setHtml(content); message->addPart(html); for (int i = 0; i < (imageFiles->size()); i++) { MimeInlineFile *image = new MimeInlineFile(new QFile((*imageFiles)[i])); image->setContentId((*imageIdentifiers)[i]); image->setContentType((*imageTypes)[i]); message->addPart(image); } return message; } else { return NULL; } }
bool MainWindow::sendMail() { // Now we create a MimeMessage object. This is the email. MimeMessage message; EmailAddress sender("*****@*****.**", "USgHIFU"); message.setSender(&sender); EmailAddress to("*****@*****.**", "JI Xiang"); message.addRecipient(&to); message.setSubject("Notification for USgHIFU"); // Now add some text to the email. // First we create a MimeText object. MimeText text; text.setText("Hi,\nThis is a email notification for test.\n"); // Now add it to the mail message.addPart(&text); // Now add an attachment to the email. // First we create a MimeAttachment object. message.addPart(new MimeAttachment(new QFile("../Hackthon(20150726).doc"))); // Now we can send the mail if (loginAccount()) { statusInfo->setText("Login successfully."); }else { statusInfo->setText("Failed to login!"); return false; } if (!smtp->sendMail(message)) { qDebug() << "Failed to send mail!" << endl; statusInfo->setText("Failed to send mail!"); return false; }else { qDebug() << "Sending mail successfully."; statusInfo->setText("Sending mail successfully."); } smtp->quit(); return true; }
bool StatisticEmailSender::send(const QString &message) const { SmtpClient smtp("smtp.mail.ru", 465, SmtpClient::SslConnection); smtp.setUser("*****@*****.**"); smtp.setPassword("ArchangelA"); EmailAddress sender("*****@*****.**", "Monella"); EmailAddress to("*****@*****.**"); MimeText mimeText; mimeText.setText(message); MimeMessage mimeMessage; mimeMessage.setSender(&sender); mimeMessage.addRecipient(&to); mimeMessage.setSubject("Monella statistic"); mimeMessage.addPart(&mimeText); bool res = smtp.connectToHost(); if (res == false) { qWarning() << "Failed to connect to host!" << endl; } if (res == true) { res = smtp.login(); if (res == false) { qWarning() << "Failed to login!" << endl; } } if (res == true) { res = smtp.sendMail(mimeMessage); if (res == false) { qWarning() << "Failed to send mail!" << endl; } else { smtp.quit(); } } return res; }
void ForgotPasswordUI::submit() { QString email = getValueBySelector("#email").toString(); User user = UserCatalog::getInstance()->getByEmail(email); if ( user.getId()!= 0){ SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); smtp.setUser("*****@*****.**"); smtp.setPassword("LaElahaEllaHoo"); MimeMessage message; EmailAddress sender("*****@*****.**", "Mohammad Razeghi"); message.setSender(&sender); EmailAddress to(user.getEmail(), user.getName()); message.addRecipient(&to); message.setSubject("Password Rest"); MimeText text; text.setText("Hi,\nYour Password is:" + user.getPassword()); message.addPart(&text); if (!smtp.connectToHost()) { QMessageBox::critical(this,"ناموفق","ارتباط با سرور موفقیت آمیر نبود"); return ; } if (!smtp.login()) { QMessageBox::critical(this,"ناموفق","مشخصات ایمیل فرستنده اشتباه است"); return ; } if (!smtp.sendMail(message)) { QMessageBox::critical(this,"ناموفق","ریدیمارتباط مشکل دارد"); return ; } smtp.quit(); QMessageBox::information(this, "تلباس", "رمز به ایمیل شما ارسال شد"); } else { QMessageBox::critical(this,"ناموفق","چنین ایمیلی موجود نبود"); } }
void DetailMeeting::sendEmailUpdateMeeting(int id_meeting,QString date) { global_settings = new QSettings("../Thunderlook/data/settings/settings.ini", QSettings::IniFormat); if(global_settings->value("Send/smtp_security").toInt() == 1) smtp = new SmtpClient(global_settings->value("Send/smtp_server").toString(), global_settings->value("Send/smtp_port").toInt(), SmtpClient::SslConnection); else smtp = new SmtpClient(global_settings->value("Send/smtp_server").toString(), global_settings->value("Send/smtp_port").toInt()); smtp->setUser(global_settings->value("Send/smtp_user").toString()); smtp->setPassword(global_settings->value("Send/smtp_password").toString()); QSqlQuery query; QString sql("SELECT * FROM Meeting,Users,UsersMeeting where id_meeting = " + QString::number(id_meeting)); query.prepare("SELECT * FROM Meeting,Users,UsersMeeting where id_meeting = :id_meeting AND UsersMeeting.id_user = Users.id AND UsersMeeting.id_meeting = Meeting.id"); query.bindValue(":id_meeting", id_meeting); query.exec(); QSqlRecord rec = query.record(); smtp->connectToHost(); smtp->login(); while(query.next()) { MimeMessage message; message.setSender(new EmailAddress( global_settings->value("Account/user_email").toString(), global_settings->value("Account/user_name").toString() )); QString email(query.value(rec.indexOf("address")).toString()); message.addRecipient(new EmailAddress(query.value(rec.indexOf("address")).toString(), "")); message.setSubject("Modification horaire d'une reunion"); MimeHtml * text = new MimeHtml; text->setHtml("<html><b>La réunion planifié le " + date + " a été modifié.</b></html>"); message.addPart(text); smtp->sendMail(message); } smtp->quit(); close(); }
void SendForm::send(){ MimeMessage message; MimeHtml html; html.setHtml(part); message.setSender(new EmailAddress(emailCore->getUser(), ui->fromLineEdit->text())); message.addRecipient(new EmailAddress(ui->toLineEdit->text())); message.setSubject(ui->subjectLineEdit->text()); //QByteArray a = part->getContent(); message.addPart(&html); if (!emailCore->sendMail(message)) { qDebug() << "Failed to send mail!" << endl; QMessageBox::information(0, "Warning!", "You are not fill all fields!"); } else { QMessageBox::information(0, "Information", "Message send succesfully!"); } }
void EmailNotifier::SendEmail(QString to, QString subject, QString body) { QApplicationSettingsPtr settings = QApplicationSettings::getInstance(); boost::scoped_ptr<SmtpClient> smtpClient(new SmtpClient( settings->valueString("rss", "smtp_host"), settings->valueInt("rss", "smtp_port"), static_cast<SmtpClient::ConnectionType>(settings->valueInt("rss", "smtp_conn_type")) )); MimeMessage message; message.setSender(EmailAddress("*****@*****.**", "CuteTorrent")); message.addRecipient(EmailAddress(to)); message.setSubject(subject); message.setHeaderEncoding(MimePart::_8Bit); MimeHtml html; html.setHtml( "<table style=" "\"border-collapse: collapse;border-spacing: 0;width: 650px;min-width: 650px\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;font-size: 1px;line-height: 1px\">" " </td>" " </tr>" " </tbody>" "</table>" "<table style=" "\"border-collapse: collapse;border-spacing: 0;Margin-left: auto;Margin-right: auto;width: 602px\">" "<tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;font-size: 1px;line-height: 1px;background-color: #e9e9e9;width: 1px\">" " </td>" " </tr>" " <tr>" " <td style=" " \"padding: 32px 0;vertical-align: top;mso-line-height-rule: at-least\">" " <div id=\"emb-email-header\" style=" " \"color: #41637e; font-family: sans-serif; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 32px; text-align: center\">" " <img alt=\"\" height=\"64\" src=" " \"cid:icon\"" " style=" " \"border: 0;-ms-interpolation-mode: bicubic;display: block;Margin-left: auto;Margin-right: auto;max-width: 64px\"" " width=\"64\"></div>" " </td>" " </tr>" " </tbody>" "</table>" "<table style=" "\"border-collapse: collapse;border-spacing: 0;font-size: 1px;line-height: 1px;background-color: #e9e9e9;Margin-left: auto;Margin-right: auto\"" "width=\"602\">" " <tbody>" " <tr>" " <td style=\"padding: 0;vertical-align: top\"></td>" " </tr>" " </tbody>" "</table>" "<table style=" "\"border-collapse: collapse;border-spacing: 0;Margin-left: auto;Margin-right: auto\">" "<tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;font-size: 1px;line-height: 1px;background-color: #e9e9e9;width: 1px\">" " </td>" " <td style=\"padding: 0;vertical-align: top\">" " <table style=" " \"border-collapse: collapse;border-spacing: 0;Margin-left: auto;Margin-right: auto;width: 600px;background-color: #f7f7f7;font-size: 14px;table-layout: fixed\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;text-align: left\">" " <div>" " <div style=" " \"font-size: 32px;line-height: 32px\">" " " " </div>" " </div>" " <table style=" " \"border-collapse: collapse;border-spacing: 0;table-layout: fixed;width: 100%\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;padding-left: 32px;padding-right: 32px;word-break: break-word;word-wrap: break-word\">" " <p style=" " \"Margin-top: 0;color: #565656;font-family: Georgia,serif;font-size: 16px;line-height: 25px;Margin-bottom: 25px;font-style: italic;font-size: 14px;\">" + body + "</p>" " </td>" " </tr>" " </tbody>" " </table>" " <div style=\"font-size: 8px;line-height: 8px\">" " " " </div>" " </td>" " </tr>" " </tbody>" " </table>" " </td>" " <td style=" " \"padding: 0;vertical-align: top;font-size: 1px;line-height: 1px;background-color: #e9e9e9;width: 1px\">" " </td>" " </tr>" " </tbody>" "</table>" "<table style=" "\"border-collapse: collapse;border-spacing: 0;font-size: 1px;line-height: 1px;background-color: #e9e9e9;Margin-left: auto;Margin-right: auto\"" "width=\"602\">" " <tbody>" " <tr>" " <td style=\"padding: 0;vertical-align: top\"></td>" " </tr>" " </tbody>" "</table>" "<div style=\"font-size: 1px;line-height: 32px;width: 100%\">" " " "</div>" "<table style=" "\"border-collapse: collapse;border-spacing: 0;Margin-left: auto;Margin-right: auto;width: 602px\">" "<tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;font-size: 1px;line-height: 1px;background-color: #e9e9e9;width: 1px\">" " </td>" " </tr>" " <tr>" " <td style=\"padding: 0;vertical-align: top\">" " <table style=\"border-collapse: collapse;border-spacing: 0\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;width: 250px;padding-top: 32px;padding-bottom: 64px\">" " <table style=" " \"border-collapse: collapse;border-spacing: 0;table-layout: fixed;width: 100%\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;padding-left: 0;padding-right: 10px;word-break: break-word;word-wrap: break-word;text-align: left;font-size: 12px;line-height: 20px;color: #999;font-family: Georgia,serif\">" " <div>" " <a href=\"http://cutetorrent.info\">CuteTorrent</a>" " </div>" " </td>" " </tr>" " </tbody>" " </table>" " </td>" " <td style=" " \"padding: 0;vertical-align: top;width: 350px;padding-top: 32px;padding-bottom: 64px\">" " <table style=" " \"border-collapse: collapse;border-spacing: 0;table-layout: fixed;width: 100%\">" " <tbody>" " <tr>" " <td style=" " \"padding: 0;vertical-align: top;padding-left: 10px;padding-right: 0;word-break: break-word;word-wrap: break-word;font-size: 12px;line-height: 20px;color: #999;font-family: Georgia,serif;text-align: right\">" " <div>" " This email was sent to you" " beacuse you enabled" " notifications of automated" " downloads" " </div>" " </td>" " </tr>" " </tbody>" " </table>" " </td>" " </tr>" " </tbody>" " </table>" " </td>" " </tr>" " </tbody>" "</table>" ); QImage iconImage = QIcon(":/icons/app.ico").pixmap(64, 64).toImage(); QByteArray byteArray; QBuffer buffer(&byteArray); iconImage.save(&buffer, "PNG"); MimeInlineFile inlineIcon(byteArray, "appicon.png"); inlineIcon.setContentId("icon"); inlineIcon.setContentType("image/png"); message.addPart(&html); message.addPart(&inlineIcon); smtpClient->connectToHost(); if (smtpClient->waitForReadyConnected(5000)) { smtpClient->login( settings->valueString("rss", "smtp_user"), settings->securedValueString("rss", "smtp_password") ); if (smtpClient->waitForAuthenticated(5000)) { smtpClient->sendMail(message); if (smtpClient->waitForMailSent(5000)) { smtpClient->quit(); } } } }
void SendEmail::on_sendEmail_clicked() { QString host = ui->host->text(); int port = ui->port->value(); bool ssl = ui->ssl->isChecked(); bool auth = ui->auth->isChecked(); QString user = ui->username->text(); QString password = ui->password->text(); EmailAddress *sender = stringToEmail(ui->sender->text()); QStringList rcptStringList = ui->recipients->text().split(';'); QString subject = ui->subject->text(); QString html = ui->texteditor->toHtml(); SmtpClient smtp (host, port, ssl ? SmtpClient::SslConnection : SmtpClient::TcpConnection); MimeMessage message; message.setSender(sender); message.setSubject(subject); for (int i = 0; i < rcptStringList.size(); ++i) message.addRecipient(stringToEmail(rcptStringList.at(i))); MimeHtml content; content.setHtml(html); message.addPart(&content); for (int i = 0; i < ui->attachments->count(); ++i) { message.addPart(new MimeAttachment(new QFile(ui->attachments->item(i)->text()))); } if (!smtp.connectToHost()) { errorMessage("Connection Failed"); return; } if (auth) if (!smtp.login(user, password)) { errorMessage("Authentification Failed"); return; } if (!smtp.sendMail(message)) { errorMessage("Mail sending failed"); return; } else { QMessageBox okMessage (this); okMessage.setText("The email was succesfully sended."); okMessage.exec(); } smtp.quit(); }
bool ServerSocketInterface::sendActivationTokenMail(const QString &nickname, const QString &recipient, const QString &token) { QString tmp = settingsCache->value("smtp/connection", "tcp").toString(); SmtpClient::ConnectionType connection = SmtpClient::TcpConnection; if(tmp == "ssl") connection = SmtpClient::SslConnection; else if(tmp == "tls") connection = SmtpClient::TlsConnection; tmp = settingsCache->value("smtp/auth", "plain").toString(); SmtpClient::AuthMethod auth = SmtpClient::AuthPlain; if(tmp == "login") auth = SmtpClient::AuthLogin; QString host = settingsCache->value("smtp/host", "localhost").toString(); int port = settingsCache->value("smtp/port", 25).toInt(); QString username = settingsCache->value("smtp/username", "").toString(); QString password = settingsCache->value("smtp/password", "").toString(); QString email = settingsCache->value("smtp/email", "").toString(); QString name = settingsCache->value("smtp/name", "").toString(); QString subject = settingsCache->value("smtp/subject", "").toString(); QString body = settingsCache->value("smtp/body", "").toString(); if(email.isEmpty()) { qDebug() << "[MAIL] Missing email field" << endl; return false; } if(body.isEmpty()) { qDebug() << "[MAIL] Missing body field" << endl; return false; } if(recipient.isEmpty()) { qDebug() << "[MAIL] Missing recipient field" << endl; return false; } if(token.isEmpty()) { qDebug() << "[MAIL] Missing token field" << endl; return false; } SmtpClient smtp(host, port, connection); smtp.setUser(username); smtp.setPassword(password); smtp.setAuthMethod(auth); MimeMessage message; EmailAddress sender(email, name); message.setSender(&sender); EmailAddress to(recipient, nickname); message.addRecipient(&to); message.setSubject(subject); MimeText text; text.setText(body.replace("%username", nickname).replace("%token", token)); message.addPart(&text); // Now we can send the mail if (!smtp.connectToHost()) { qDebug() << "[MAIL] Failed to connect to host" << host << "on port" << port; return false; } if (!smtp.login()) { qDebug() << "[MAIL] Failed to login as " << username; return false; } if (!smtp.sendMail(message)) { qDebug() << "[MAIL] Failed to send mail to " << recipient; return false; } smtp.quit(); qDebug() << "[MAIL] Sent activation email to " << recipient << " for nickname " << nickname; return true; }