How to send mails with polish letters?
-
Hello,
I have the code from here:
https://github.com/xcoder123/SimpleSmtp_SSL_QT5/tree/master/smtp_attachements
I would like to send mails with polish letters. I have very strange result. I talk about bodies:
What I send: ĄĘĆŻŹ
What I receive: • ∆ØèWhat I send: ĄĘĆŁÓŃŚ
What I receive: ¥تئ£سرŒWhat I send: błąd
What I receive: b彻dWhat I send: Błędy, które otrzymałem to
What I receive: Błędy, które otrzymałem toIn the last example I get what I want.
I try change:
message.append( "Content-Type: text/plain\n\n" ); message.append(body); message.append("\n\n");
to:
message.append( "Content-Type: text/plain; charset=UTF-8\n\n" ); message.append(body); message.append("\n\n");
But I get the same values ( not good result ).
-
@jsulm
message is QString. This is a argument in sendMail(), which I show in the previous post.Where I receive mail? I don't understand the question. I send it to my gmail account.
EDIT
@jsulm I think I have solution, but I check this only one time. But I have other question to you. My solution:
I change:*t << message << "\r\n.\r\n"; //// t is QTextStream t->flush(); state = Quit;
to:
auto x = t->codec(); t->setCodec("UTF-8"); *t << message << "\r\n.\r\n"; t->flush(); t->setCodec(x); state = Quit;
And the question: what with this "x" variable? I have to delete it after setCodec()?
-
@jsulm Yeah, I forget about that. My app is GUI app And I do something like that:
The messageEdit is QPlainTextEdit. I execute function sendMail when I click on button:
smtp->sendMail("abc@onet.pl", "def@gmail.com" , subjectEdit->text().isEmpty()?"brak tematu":subjectEdit->text(), messageEdit->toPlainText(), files );
next I go to sendMail function, which looks like:
void sendMail(const QString &from, const QString &to, const QString &subject, const QString &body, QStringList files)
And in this function I have:
message = "To: " + to + "\n"; message.append("From: " + from + "\n"); message.append("Subject: " + subject + "\n"); 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/plain; charset=UTF-8\n\n" ); message.append(body); message.append("\n\n");
And below I have:
else if ( state == Body && responseLine == "354" ) { *t << message << "\r\n.\r\n"; t->flush(); state = Quit; }
t is QTextStream
EDIT
So I get body from QPlainTextEdit using toPlainText(). -
@jsulm
message is QString. This is a argument in sendMail(), which I show in the previous post.Where I receive mail? I don't understand the question. I send it to my gmail account.
EDIT
@jsulm I think I have solution, but I check this only one time. But I have other question to you. My solution:
I change:*t << message << "\r\n.\r\n"; //// t is QTextStream t->flush(); state = Quit;
to:
auto x = t->codec(); t->setCodec("UTF-8"); *t << message << "\r\n.\r\n"; t->flush(); t->setCodec(x); state = Quit;
And the question: what with this "x" variable? I have to delete it after setCodec()?