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,"ناموفق","چنین ایمیلی موجود نبود");
    }

}
Пример #3
0
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();
}
Пример #4
0
bool SmtpClient::sendMail(MimeMessage& email)
{
    try
    {
        // Send the MAIL command with the sender
        sendMessage("MAIL FROM: <" + email.getSender().getAddress() + ">");

        waitForResponse();

        if (responseCode != 250) return false;

        // Send RCPT command for each recipient
        for (int i = 0; i < email.getRecipients().size(); ++i)
        {
            sendMessage("RCPT TO: <" + email.getRecipients().at(i)->getAddress() + ">");
            waitForResponse();

            if (responseCode != 250) return false;
        }

        // Send DATA command
        sendMessage("DATA");
        waitForResponse();

        if (responseCode != 354) return false;

        sendMessage(email.toString());

        // Send \r\n.\r\n to end the mail data
        sendMessage(".");

        waitForResponse();

        if (responseCode != 250) return false;
    }
    catch (ResponseTimeoutException)
    {
        return false;
    }

    return true;
}
Пример #5
0
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!");
    }


}
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;
    }
}
Пример #7
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // First create the SmtpClient object and set the user and the password.

    Sender smtp(QLatin1String("smtp.gmail.com"), 465, Sender::SslConnection);

    smtp.setUser(QLatin1String("*****@*****.**"));
    smtp.setPassword(QLatin1String("your_password"));

    // Create a MimeMessage

    MimeMessage message;

    EmailAddress sender(QLatin1String("*****@*****.**"), QLatin1String("Your Name"));
    message.setSender(sender);

    EmailAddress to(QLatin1String("*****@*****.**"), QLatin1String("Recipient's Name"));
    message.addTo(to);

    message.setSubject(QLatin1String("SmtpClient for Qt - Example 4 - Html email with images"));

    // Now we need to create a MimeHtml object for HTML content
    MimeHtml html;

    html.setHtml(QLatin1String("<h1> Hello! </h1>"
                               "<h2> This is the first image </h2>"
                               "<img src='cid:image1' />"
                               "<h2> This is the second image </h2>"
                               "<img src='cid:image2' />"));


    // Create a MimeInlineFile object for each image
    MimeInlineFile image1 (new QFile(QLatin1String("image1.jpg")));

    // An unique content id must be setted
    image1.setContentId(QByteArrayLiteral("image1"));
    image1.setContentType(QByteArrayLiteral("image/jpg"));

    MimeInlineFile image2 (new QFile(QLatin1String("image2.jpg")));
    image2.setContentId(QByteArrayLiteral("image2"));
    image2.setContentType(QByteArrayLiteral("image/jpg"));

    message.addPart(&html);
    message.addPart(&image1);
    message.addPart(&image2);

    // Now the email can be sended
    if (!smtp.sendMail(message)) {
        qDebug() << "Failed to send mail!" << smtp.lastError();
        return -3;
    }

    smtp.quit();

}
Пример #8
0
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;
}
Пример #9
0
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\">"
	    "			&nbsp;</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\">"
	    "			&nbsp;</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\">"
	    "										&nbsp;"
	    "									</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\">"
	    "									&nbsp;"
	    "								</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%\">"
	    "	&nbsp;"
	    "</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\">"
	    "			&nbsp;</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();
			}
		}
	}
}
Пример #10
0
bool SmtpClient::sendMail(MimeMessage& email)
{
    try
    {
        // Send the MAIL command with the sender
        sendMessage("MAIL FROM: <" + email.getSender().getAddress() + ">");

        waitForResponse();

        if (responseCode != 250) return false;

        // Send RCPT command for each recipient
        QList<EmailAddress*>::const_iterator it, itEnd;
        // To (primary recipients)
        for (it = email.getRecipients().begin(), itEnd = email.getRecipients().end();
             it != itEnd; ++it)
        {
            sendMessage("RCPT TO: <" + (*it)->getAddress() + ">");
            waitForResponse();

            if (responseCode != 250) return false;
        }

        // Cc (carbon copy)
        for (it = email.getRecipients(MimeMessage::Cc).begin(), itEnd = email.getRecipients(MimeMessage::Cc).end();
             it != itEnd; ++it)
        {
            sendMessage("RCPT TO: <" + (*it)->getAddress() + ">");
            waitForResponse();

            if (responseCode != 250) return false;
        }

        // Bcc (blind carbon copy)
        for (it = email.getRecipients(MimeMessage::Bcc).begin(), itEnd = email.getRecipients(MimeMessage::Bcc).end();
             it != itEnd; ++it)
        {
            sendMessage("RCPT TO: <" + (*it)->getAddress() + ">");
            waitForResponse();

            if (responseCode != 250) return false;
        }
        // Send DATA command
        sendMessage("DATA");
        waitForResponse();

        if (responseCode != 354) return false;

        sendMessage(email.toString());

        // Send \r\n.\r\n to end the mail data
        sendMessage(".");

        waitForResponse();

        if (responseCode != 250) return false;
    }
    catch (ResponseTimeoutException)
    {
        return false;
    }
    catch (SendMessageTimeoutException)
    {
        return false;
    }

    return true;
}
bool
NavCellHandler::handleCell( UserItem* userItem, 
                            NavRequestPacket* req, 
                            NavReplyPacket* reply )
{
   if ( !checkExpectations( req->getParamBlock(), reply ) ) {
      return false;
   }

   bool ok = true;

   // The params
   const NParamBlock& params = req->getParamBlock();
   NParamBlock& rparams = reply->getParamBlock();
   // The user
   UserUser* user = userItem->getUser();

   // Start parameter printing
   mc2log << info << "handleCell:";

   if ( params.getParam( 5000 ) && 
        params.getParam( 5000 )->getLength() >= 5*2 ) 
   {
      mc2log << " Data length " << params.getParam( 5000 )->getLength()
             << endl;

      uint32 pos = 0;
      uint16 cellPackProtoVer = params.getParam( 5000 )->getUint16( pos );
      pos += 2;
      uint16 cellPackID = params.getParam( 5000 )->getUint16( pos );
      pos += 2;
      /*uint16 cellPackType =*/ params.getParam( 5000 )->getUint16( pos );
      pos += 2;
      /*uint16 cellPackPartNbr=*/params.getParam( 5000 )->getUint16( pos );
      pos += 2;
      /*uint16 cellPackTotalPartNbr =*/ params.getParam( 5000 )
         ->getUint16( pos );
      pos += 2;
      

      // Mailto logs
      MimeMessage* m = new MimeMessage( 
         MimePartApplication::getContentTypeAsString(
            MimePartApplication::CONTENT_TYPE_APPLICATION_OCTETSTREAM ) );
      m->add( new MimePartApplication( 
                 const_cast<byte*>( params.getParam( 5000 )->getBuff() ), 
                 params.getParam( 5000 )->getLength(), 
                 MimePartApplication::CONTENT_TYPE_APPLICATION_OCTETSTREAM,
                 "", true ) );
      
      bool sentOk = false;
      SendEmailRequestPacket* p = new SendEmailRequestPacket( 0 );
      char* body = m->getMimeMessageBody();
      const char* optionalHeaderTypes[ 2 ] = 
         { MimeMessage::mimeVersionHeader, 
           MimeMessage::contentTypeHeader };
      const char* optionalHeaderValues[ 2 ] = 
         { m->getMimeVersion(), m->getContentType() };
      MC2String sender( Properties::getProperty( 
         "DEFAULT_RETURN_EMAIL_ADDRESS", 
         "*****@*****.**" ) );

      if ( user->getEmailAddress()[ 0 ] != '\0' ) {
         sender = user->getEmailAddress();
      } else {
         sender = user->getLogonID();
         // Make it a valid email-address
         sender.append( "@localhost.localdomain" );
      }
      
      if ( p->setData( "*****@*****.**", 
                       sender.c_str(), "my logfiles", body,
                       2, optionalHeaderTypes, optionalHeaderValues ) )
      {
         PacketContainer* rp = new PacketContainer( p, 0, 0 , 
                                                    MODULE_TYPE_SMTP );
         PacketContainer* pc = m_thread->putRequest( rp );
         if ( pc != NULL && static_cast< ReplyPacket* >( pc->getPacket() )
              ->getStatus() == StringTable::OK )
         {
            sentOk = true; 
         }
         delete pc;
      } else {
         mc2log << error << "handleCell "
                << "SendEmailRequestPacket::setData failed." << endl;
      }
      
      delete [] body;
      delete m;
      
      if ( !sentOk ) {
         Utility::hexDump( 
            mc2log, 
            const_cast<byte*>( params.getParam( 5000 )->getBuff() ),
            params.getParam( 5000 )->getLength() );
      }

      // The reply data
      NParam& replyData = rparams.addParam( NParam( 5100 ) );

      replyData.addUint32( 5*2 );
      // Write cell packet header 
      // protocol version, 2 bytes, currently always zero.
      replyData.addUint16( cellPackProtoVer );
      // packet id, 2 bytes, a sequential number
      replyData.addUint16( cellPackID );
      // packet type, 2 bytes, 0x8000 for acknowledge.
      replyData.addUint16( 0x8000 );
      // packet part number, 2 bytes, 0-based (0 for ack)
      replyData.addUint16( 0 );
      // total number of parts, 2 bytes, 0-based (0 for ack)
      replyData.addUint16( 0 );
      
      mc2log << info << "handleCell reply: "
             << " size " << replyData.getLength() << endl;
   } else {
      mc2log << " No data!" << endl;
   }


   return ok;
}
Пример #12
0
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;
}
Пример #14
0
bool SenderPrivate::sendMail(MimeMessage &email)
{
    qCDebug(SIMPLEMAIL_SENDER) << "Sending MAIL" << this;

    if (!processState()) {
        return false;
    }

    qCDebug(SIMPLEMAIL_SENDER) << "Sending MAIL command";
    // Send the MAIL command with the sender
    sendMessage("MAIL FROM: <" + email.sender().address().toLatin1() + '>');
    if (!waitForResponse(250)) {
        return false;
    }

    qCDebug(SIMPLEMAIL_SENDER) << "Sending RCPT TO command";
    // Send RCPT command for each recipient
    // To (primary recipients)
    Q_FOREACH (const EmailAddress &rcpt, email.toRecipients()) {
        sendMessage("RCPT TO: <" + rcpt.address().toLatin1() + '>');

        if (!waitForResponse(250)) {
            return false;
        }
    }

    // Cc (carbon copy)
    Q_FOREACH (const EmailAddress &rcpt, email.ccRecipients()) {
        sendMessage("RCPT TO: <" + rcpt.address().toLatin1() + '>');

        if (!waitForResponse(250)) {
            return false;
        }
    }

    // Bcc (blind carbon copy)
    Q_FOREACH (const EmailAddress &rcpt, email.bccRecipients()) {
        sendMessage("RCPT TO: <" + rcpt.address().toLatin1() + '>');

        if (!waitForResponse(250)) {
            return false;
        }
    }

    qCDebug(SIMPLEMAIL_SENDER) << "Sending DATA command";
    // Send DATA command
    sendMessage(QByteArrayLiteral("DATA"));

    if (!waitForResponse(354)) {
        return false;
    }

    qCDebug(SIMPLEMAIL_SENDER) << "Sending email";
    if (!email.write(socket)) {
        return false;
    }

    // Send \r\n.\r\n to end the mail data
    sendMessage(QByteArrayLiteral("\r\n."));
    if (!waitForResponse(250)) {
        return false;
    }
    qCDebug(SIMPLEMAIL_SENDER) << "Mail sent";

    return true;
}
Пример #15
0
QByteArray ViewEmail::render(Context *c) const
{
    Q_D(const ViewEmail);

    QVariantHash email = c->stash(d->stashKey).toHash();
    if (email.isEmpty()) {
        c->error(QStringLiteral("Cannot render template, template name or template stash key not defined"));
        return QByteArray();
    }

    MimeMessage message;

    QVariant value;
    value = email.value(QStringLiteral("to"));
    if (value.type() == QVariant::String && !value.toString().isEmpty()) {
        message.addTo(value.toString());
    }

    value = email.value(QStringLiteral("cc"));
    if (value.type() == QVariant::String && !value.toString().isEmpty()) {
        message.addCc(value.toString());
    }

    value = email.value(QStringLiteral("from"));
    if (value.type() == QVariant::String && !value.toString().isEmpty()) {
        message.setSender(value.toString());
    }

    value = email.value(QStringLiteral("subject"));
    if (value.type() == QVariant::String && !value.toString().isEmpty()) {
        message.setSubject(value.toString());
    }

    QVariant body = email.value(QStringLiteral("body"));
    QVariant parts = email.value(QStringLiteral("parts"));
    if (body.isNull() && parts.isNull()) {
        c->error(QStringLiteral("Can't send email without parts or body, check stash"));
        return QByteArray();
    }

    if (!parts.isNull()) {
        const QVariantList partsVariant = parts.toList();
        Q_FOREACH (const QVariant &part, partsVariant) {
            MimePart *mime = part.value<MimePart*>();
            if (mime) {
                message.addPart(mime);
            } else {
                qCCritical(CUTELYST_VIEW_EMAIL) << "Failed to cast MimePart";
            }
        }

        auto contentTypeIt = email.constFind(QStringLiteral("content_type"));
        if (contentTypeIt != email.constEnd()
                && !contentTypeIt.value().isNull()
                && !contentTypeIt.value().toString().isEmpty()) {
            const QByteArray contentType = contentTypeIt.value().toString().toLatin1();
            qCDebug(CUTELYST_VIEW_EMAIL) << "Using specified content_type" << contentType;
            message.getContent().setContentType(contentType);
        } else if (!d->defaultContentType.isEmpty()) {
            qCDebug(CUTELYST_VIEW_EMAIL) << "Using default content_type" << d->defaultContentType;
            message.getContent().setContentType(d->defaultContentType);
        }
    } else {