Results 1 to 3 of 3

Thread: MIME and smtp

  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question MIME and smtp

    Hello!

    I have read some threads on this forum related to smtp and attachments and I've read rfc's related to MIME, but still I have a problem. I believe it's only because of my misunderstanding.

    I tried to send the message with html-body and the picture. But as a result I can send either message or picture.
    Here is the code related to the mail body:
    Qt Code:
    1. "MIME-Version: 1.0\r\n"
    2. "Content-Type: multipart/mixed\r\n"
    3. "Received: from support@support.com\r\n"
    4. "Date: " + date.toString() + "\r\n"
    5. "From: Dude\r\n"
    6. "To: Dude\r\n"
    7. "Subject: Your PC is infected by our company\r\n"
    8. "Content-Type: text/html; charset=UNICODE-1-1-UTF-7\r\n"
    9. "<h1>Hello, dude!!!ääääää</h1>"
    10. "Content-Type: image/jpg; name=pic.jpg\r\n"
    11. "Content-Transfer-Encoding: base64\r\n" +
    12. str +
    13. "\r\n.\r\n"
    To copy to clipboard, switch view to plain text mode 

    str is base64-encoded string.

    I know about boundaries, but here is another problem: MIME didn't process them, and I saw in the message something like: --_________boundary-uniq-1;
    What am I doing wrong? How it can be changed?

    Thank you for answers beforehand.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: MIME and smtp

    You should specify a boundary on line 2 and use it before each part of the message. Each part of the message should specify a content type, and possible other header, and a blank line (missing above) before the actual content. See http://en.wikipedia.org/wiki/MIME#Multipart_messages for a simple example.

  3. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (15th September 2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: MIME and smtp

    Thank you!

    If someone has the same problem, here is the code:

    Qt Code:
    1. "Received: from support@microsoft.com\r\n"
    2. "Date: " + date.toString() + "\r\n"
    3. "From: Dude\r\n"
    4. "To: Dude\r\n"
    5. "Subject: Your PC is infected by our company\r\n"
    6. "MIME-Version: 1.0\r\n"
    7. "Content-Type: multipart/related; boundary=_markeraaaaa\r\n"
    8. "\r\n"
    9. "--_markeraaaaa\r\n"
    10. "Content-Type: text/html; charset=UNICODE-1-1-UTF-7\r\n"
    11. "\r\n"
    12. "<h1>Hello, dude!!!ääääää</h1>\r\n"
    13. "--_markeraaaaa\r\n"
    14. "Content-Type: image/jpeg; name=pic.jpg\r\n"
    15. "Content-Transfer-Encoding: base64\r\n"
    16. "\r\n" +
    17. str + "\r\n" +
    18. "--_markeraaaaa--\r\n"
    19. "\r\n.\r\n"
    To copy to clipboard, switch view to plain text mode 


    By the message, which is written above we will send one line of text and the picture. str is that picture, which was base64-encoded. For instance, in this way:
    Qt Code:
    1. QFile file("E:\\linux-penguin-computing.jpg");
    2. file.open(QIODevice::ReadOnly);
    3. QString str = file.readAll().toBase64() + "\r\n";
    4. file.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by DmitryNik; 15th September 2011 at 09:00. Reason: putting some code for people, who has the same problem.

Similar Threads

  1. SMTP Client for Qt
    By bluetiger9 in forum Qt-based Software
    Replies: 8
    Last Post: 16th October 2013, 04:10
  2. Sending SMTP Email
    By azfar in forum Newbie
    Replies: 1
    Last Post: 30th April 2011, 20:25
  3. SMTP: how to request confirmation?
    By Raccoon29 in forum General Programming
    Replies: 2
    Last Post: 28th January 2009, 15:41
  4. Attachment files to email (SMTP/MIME)
    By henriquez0 in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2006, 20:56
  5. SMTP & Attachments
    By cioannou in forum General Programming
    Replies: 2
    Last Post: 26th January 2006, 12:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.