Qt Smtp Mail Sender - Outlook Encoder Problem
-
wrote on 7 Jul 2017, 07:46 last edited by
Hello I'm sending messages from my program but in Outlook the text seems bad shift.
smt->sendMail("from", "to","DaxiClient - " + ui->cmbSubject->currentText(), "<b>დასახელება:</b> " + ui->lnObjectName->text() + "<br>" + "<b>ს/კ:</b> " + ui->lnSk->text() + "<br>" + "<b>ტელეფონი:</b> " + ui->lnMobile->text() + "<br>" + "<b>E-Mail:</b> " + ui->lnEmail->text() + "<br><br><br>" + "<b>წერილი:</b> " + "<br>" + ui->txtText->toPlainText().toHtmlEscaped().toUtf8());
void smtp::sendMail(const QString &from, const QString &to, const QString &subject, const QString &body, QStringList files) { qDebug() << "sent begin"; message = "To: " + to + "\n"; message.append("From: " + from + "\n"); message.append("Subject: " + subject + "\n"); //Let's intitiate multipart MIME with cutting boundary "frontier" message.append("MIME-Version: 1.0\n"); message.append("Content-Type: multipart/mixed; boundary=frontier\n\n"); message.append( "--frontier\n" ); //message.append( "Content-Type: text/html\n\n" ); //Uncomment this for HTML formating, coment the line below message.append( "Content-Type: text/html\n\n" ); message.append(body); message.append("\n\n"); if(!files.isEmpty()) { qDebug() << "Files to be sent: " << files.size(); foreach(QString filePath, files) { QFile file(filePath); if(file.exists()) { if (!file.open(QIODevice::ReadOnly)) { qDebug("Couldn't open the file"); QMessageBox::warning( 0, tr( "Qt Simple SMTP client" ), tr( "Couldn't open the file\n\n" ) ); return ; } QByteArray bytes = file.readAll(); message.append( "--frontier\n" ); message.append( "Content-Type: application/octet-stream\nContent-Disposition: attachment; filename="+ QFileInfo(file.fileName()).fileName() +";\nContent-Transfer-Encoding: base64\n\n" ); message.append(bytes.toBase64()); message.append("\n"); } } } else qDebug() << "No attachments found"; message.append( "--frontier--\n" ); message.replace( QString::fromLatin1( "\n" ), QString::fromLatin1( "\r\n" ) ); message.replace( QString::fromLatin1( "\r\n.\r\n" ),QString::fromLatin1( "\r\n..\r\n" ) ); this->from = from; rcpt = to; state = Init; socket->connectToHostEncrypted(host, port); //"smtp.gmail.com" and 465 for gmail TLS if (!socket->waitForConnected(timeout)) { qDebug() << socket->errorString(); } t = new QTextStream( socket ); t->setCodec("UTF-8");
t is QTextStream
-
wrote on 7 Jul 2017, 09:01 last edited by
Its Solved :)
@Taz742 said in Qt Smtp Mail Sender - Outlook Encoder Problem:
message.append("Content-Type: multipart/mixed; boundary=frontier\n\n");
reply:
message.append("Content-Type: multipart/mixed; boundary=frontier; charset=UTF-8\n\n")
-
Hello I'm sending messages from my program but in Outlook the text seems bad shift.
smt->sendMail("from", "to","DaxiClient - " + ui->cmbSubject->currentText(), "<b>დასახელება:</b> " + ui->lnObjectName->text() + "<br>" + "<b>ს/კ:</b> " + ui->lnSk->text() + "<br>" + "<b>ტელეფონი:</b> " + ui->lnMobile->text() + "<br>" + "<b>E-Mail:</b> " + ui->lnEmail->text() + "<br><br><br>" + "<b>წერილი:</b> " + "<br>" + ui->txtText->toPlainText().toHtmlEscaped().toUtf8());
void smtp::sendMail(const QString &from, const QString &to, const QString &subject, const QString &body, QStringList files) { qDebug() << "sent begin"; message = "To: " + to + "\n"; message.append("From: " + from + "\n"); message.append("Subject: " + subject + "\n"); //Let's intitiate multipart MIME with cutting boundary "frontier" message.append("MIME-Version: 1.0\n"); message.append("Content-Type: multipart/mixed; boundary=frontier\n\n"); message.append( "--frontier\n" ); //message.append( "Content-Type: text/html\n\n" ); //Uncomment this for HTML formating, coment the line below message.append( "Content-Type: text/html\n\n" ); message.append(body); message.append("\n\n"); if(!files.isEmpty()) { qDebug() << "Files to be sent: " << files.size(); foreach(QString filePath, files) { QFile file(filePath); if(file.exists()) { if (!file.open(QIODevice::ReadOnly)) { qDebug("Couldn't open the file"); QMessageBox::warning( 0, tr( "Qt Simple SMTP client" ), tr( "Couldn't open the file\n\n" ) ); return ; } QByteArray bytes = file.readAll(); message.append( "--frontier\n" ); message.append( "Content-Type: application/octet-stream\nContent-Disposition: attachment; filename="+ QFileInfo(file.fileName()).fileName() +";\nContent-Transfer-Encoding: base64\n\n" ); message.append(bytes.toBase64()); message.append("\n"); } } } else qDebug() << "No attachments found"; message.append( "--frontier--\n" ); message.replace( QString::fromLatin1( "\n" ), QString::fromLatin1( "\r\n" ) ); message.replace( QString::fromLatin1( "\r\n.\r\n" ),QString::fromLatin1( "\r\n..\r\n" ) ); this->from = from; rcpt = to; state = Init; socket->connectToHostEncrypted(host, port); //"smtp.gmail.com" and 465 for gmail TLS if (!socket->waitForConnected(timeout)) { qDebug() << socket->errorString(); } t = new QTextStream( socket ); t->setCodec("UTF-8");
t is QTextStream
Moderatorswrote on 7 Jul 2017, 07:59 last edited by raven-worx 7 Jul 2017, 08:00@Taz742 said in Qt Smtp Mail Sender - Outlook Encoder Problem:
Hello I'm sending messages from my program but in Outlook the text seems bad shift.
smt->sendMail("from", "to","DaxiClient - " + ui->cmbSubject->currentText(),
"<b>დასახელება:</b> " + ui->lnObjectName->text() + "<br>" +
"<b>ს/კ:</b> " + ui->lnSk->text() + "<br>" +
"<b>ტელეფონი:</b> " + ui->lnMobile->text() + "<br>" +
"<b>E-Mail:</b> " + ui->lnEmail->text() + "<br><br><br>" +
"<b>წერილი:</b> " + "<br>" +
ui->txtText->toPlainText().toHtmlEscaped().toUtf8());what do you mean by "bad shift"?
Are your source files UTF-8 encoded?
Since you wrote your encoded text directly into the source file the encoding gets most probably messed up.For example try
QString::fromUtf8("\xE1\x83\x93\xE1\x83\x90\xE1\x83\xA1\xE1\x83\x90\xE1\x83\xAE\xE1\x83\x94\xE1\x83\x9A\xE1\x83\x94\xE1\x83\x91\xE1\x83\x90")
forდასახელება
instead and check if it's working. -
@Taz742 said in Qt Smtp Mail Sender - Outlook Encoder Problem:
Hello I'm sending messages from my program but in Outlook the text seems bad shift.
smt->sendMail("from", "to","DaxiClient - " + ui->cmbSubject->currentText(),
"<b>დასახელება:</b> " + ui->lnObjectName->text() + "<br>" +
"<b>ს/კ:</b> " + ui->lnSk->text() + "<br>" +
"<b>ტელეფონი:</b> " + ui->lnMobile->text() + "<br>" +
"<b>E-Mail:</b> " + ui->lnEmail->text() + "<br><br><br>" +
"<b>წერილი:</b> " + "<br>" +
ui->txtText->toPlainText().toHtmlEscaped().toUtf8());what do you mean by "bad shift"?
Are your source files UTF-8 encoded?
Since you wrote your encoded text directly into the source file the encoding gets most probably messed up.For example try
QString::fromUtf8("\xE1\x83\x93\xE1\x83\x90\xE1\x83\xA1\xE1\x83\x90\xE1\x83\xAE\xE1\x83\x94\xE1\x83\x9A\xE1\x83\x94\xE1\x83\x91\xE1\x83\x90")
forდასახელება
instead and check if it's working.wrote on 7 Jul 2017, 08:08 last edited by@raven-worx said in Qt Smtp Mail Sender - Outlook Encoder Problem:
what do you mean by "bad shift"?
А┐⌠А┐░А┐║А┐░А┐╝А┐■А┐ А┐■А┐▒А┐░: 1
А┐║/А┐≥: 1
А┐╒А┐■А┐ А┐■А┐╓А┐²А┐°А┐≤: 1
E-Mail: 1А┐╛А┐■А┐═А┐≤А┐ А┐≤:
1@raven-worx said in Qt Smtp Mail Sender - Outlook Encoder Problem:
For example try QString::fromUtf8("\xE1\x83\x93\xE1\x83\x90\xE1\x83\xA1\xE1\x83\x90\xE1\x83\xAE\xE1\x83\x94\xE1\x83\x9A\xE1\x83\x94\xE1\x83\x91\xE1\x83\x90") for დასახელება instead and check if it's working.
Everything remains the same
-
@raven-worx said in Qt Smtp Mail Sender - Outlook Encoder Problem:
what do you mean by "bad shift"?
А┐⌠А┐░А┐║А┐░А┐╝А┐■А┐ А┐■А┐▒А┐░: 1
А┐║/А┐≥: 1
А┐╒А┐■А┐ А┐■А┐╓А┐²А┐°А┐≤: 1
E-Mail: 1А┐╛А┐■А┐═А┐≤А┐ А┐≤:
1@raven-worx said in Qt Smtp Mail Sender - Outlook Encoder Problem:
For example try QString::fromUtf8("\xE1\x83\x93\xE1\x83\x90\xE1\x83\xA1\xE1\x83\x90\xE1\x83\xAE\xE1\x83\x94\xE1\x83\x9A\xE1\x83\x94\xE1\x83\x91\xE1\x83\x90") for დასახელება instead and check if it's working.
Everything remains the same
wrote on 7 Jul 2017, 08:10 last edited byWhen I enter E-mail web page everything looks good there.
-
wrote on 7 Jul 2017, 09:01 last edited by
Its Solved :)
@Taz742 said in Qt Smtp Mail Sender - Outlook Encoder Problem:
message.append("Content-Type: multipart/mixed; boundary=frontier\n\n");
reply:
message.append("Content-Type: multipart/mixed; boundary=frontier; charset=UTF-8\n\n")
1/5