Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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彻d

    What I send: Błędy, które otrzymałem to
    What I receive: Błędy, które otrzymałem to

    In 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()?


  • Qt Champions 2019

    @TomNow99 From where and how do you get the text you want to send?



  • @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().


  • Qt Champions 2019

    @TomNow99 What is "message". Is it QString?
    Where do you receive the mail and what encoding is set there?



  • @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()?



  • This post is deleted!

Log in to reply