Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Smtp Mail Sender - Outlook Encoder Problem
QtWS25 Last Chance

Qt Smtp Mail Sender - Outlook Encoder Problem

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taz742
    wrote on 7 Jul 2017, 07:46 last edited by
    #1

    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

    Do what you want.

    R 1 Reply Last reply 7 Jul 2017, 07:59
    0
    • T Taz742
      7 Jul 2017, 08:10

      When I enter E-mail web page everything looks good there.

      T Offline
      T Offline
      Taz742
      wrote on 7 Jul 2017, 09:01 last edited by
      #5

      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")
      

      Do what you want.

      1 Reply Last reply
      2
      • T Taz742
        7 Jul 2017, 07:46

        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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 7 Jul 2017, 07:59 last edited by raven-worx 7 Jul 2017, 08:00
        #2

        @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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        T 1 Reply Last reply 7 Jul 2017, 08:08
        0
        • R raven-worx
          7 Jul 2017, 07:59

          @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.

          T Offline
          T Offline
          Taz742
          wrote on 7 Jul 2017, 08:08 last edited by
          #3

          @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

          Do what you want.

          T 1 Reply Last reply 7 Jul 2017, 08:10
          0
          • T Taz742
            7 Jul 2017, 08:08

            @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

            T Offline
            T Offline
            Taz742
            wrote on 7 Jul 2017, 08:10 last edited by
            #4

            When I enter E-mail web page everything looks good there.

            Do what you want.

            T 1 Reply Last reply 7 Jul 2017, 09:01
            0
            • T Taz742
              7 Jul 2017, 08:10

              When I enter E-mail web page everything looks good there.

              T Offline
              T Offline
              Taz742
              wrote on 7 Jul 2017, 09:01 last edited by
              #5

              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")
              

              Do what you want.

              1 Reply Last reply
              2

              1/5

              7 Jul 2017, 07:46

              • Login

              • Login or register to search.
              1 out of 5
              • First post
                1/5
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved