Email current note.
| 2718 | |
| 2719 | // Email current note. |
| 2720 | void NBrowserWindow::emailNote() { |
| 2721 | global.settings->beginGroup("Email"); |
| 2722 | QString server = global.settings->value("smtpServer", "").toString(); |
| 2723 | int port = global.settings->value("smtpPort", 25).toInt(); |
| 2724 | QString smtpConnectionType = global.settings->value("smtpConnectionType", "TcpConnection").toString(); |
| 2725 | QString userid = global.settings->value("userid", "").toString(); |
| 2726 | QString password = global.settings->value("password", "").toString(); |
| 2727 | QString senderEmail = global.settings->value("senderEmail", "").toString(); |
| 2728 | QString senderName = global.settings->value("senderName", "").toString(); |
| 2729 | global.settings->endGroup(); |
| 2730 | |
| 2731 | if (senderEmail.trimmed() == "" || server.trimmed() == "") { |
| 2732 | QMessageBox::critical(this, tr("Setup Error"), |
| 2733 | tr("SMTP Server has not been setup.\n\nPlease specify server settings\nin the Preferences menu."), QMessageBox::Ok); |
| 2734 | return; |
| 2735 | } |
| 2736 | |
| 2737 | EmailDialog emailDialog; |
| 2738 | emailDialog.subject->setText(noteTitle.text()); |
| 2739 | emailDialog.exec(); |
| 2740 | if (emailDialog.cancelPressed) |
| 2741 | return; |
| 2742 | emit(setMessage(tr("Sending Email. Please be patient."))); |
| 2743 | |
| 2744 | QStringList toAddresses = emailDialog.getToAddresses(); |
| 2745 | QStringList ccAddresses = emailDialog.getCcAddresses(); |
| 2746 | QStringList bccAddresses = emailDialog.getBccAddresses(); |
| 2747 | |
| 2748 | if (senderName.trimmed() == "") |
| 2749 | senderName = senderEmail; |
| 2750 | |
| 2751 | SmtpClient::ConnectionType type = SmtpClient::TcpConnection; |
| 2752 | if (smtpConnectionType == "SslConnection") |
| 2753 | type = SmtpClient::SslConnection; |
| 2754 | if (smtpConnectionType == "TlsConnection") |
| 2755 | type = SmtpClient::TlsConnection; |
| 2756 | |
| 2757 | SmtpClient smtp(server, port, type); |
| 2758 | smtp.setResponseTimeout(-1); |
| 2759 | |
| 2760 | // We need to set the username (your email address) and password |
| 2761 | // for smtp authentication. |
| 2762 | smtp.setUser(userid); |
| 2763 | smtp.setPassword(password); |
| 2764 | |
| 2765 | // Now we create a MimeMessage object. This is the email. |
| 2766 | MimeMessage message; |
| 2767 | |
| 2768 | EmailAddress sender(senderEmail, senderName); |
| 2769 | message.setSender(&sender); |
| 2770 | |
| 2771 | for (int i=0; i<toAddresses.size(); i++) { |
| 2772 | EmailAddress *to = new EmailAddress(toAddresses[i], toAddresses[i]); |
| 2773 | message.addRecipient(to); |
| 2774 | } |
| 2775 | |
| 2776 | for (int i=0; i<ccAddresses.size(); i++) { |
| 2777 | EmailAddress *cc = new EmailAddress(ccAddresses[i], ccAddresses[i]); |
nothing calls this directly
no test coverage detected