Results 1 to 12 of 12

Thread: SMTP tag for attaching file

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default SMTP tag for attaching file

    Hi,
    While sending a mail, the recipient receives the mail with all the contents of the file as a text. I dont want the file contents to be shown directly. I want the file to sent as an attachment to mail. As per my analysis, the following are the standard tags read by SMTP. Now to attach a file there has to be some tag which will tell SMTP to attach it. Please help me to find the tag and where it should be placed in the example below.

    HELO there
    MAIL FROM : < xyz@gmail.com >
    RCPT TO : < abc@yahoo.com >
    DATA
    From: xyz@gmail.com
    To: abc@yahoo.com
    Subject: Hi..!!!
    Hello How are u...???
    QUIT
    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Hi guys,
    Got it... Please let me know if I'm wrong...
    Added this string after DATA tag
    Qt Code:
    1. QString header;
    2. header += QString("Mime-version: 1.0") + QString("\r\n");
    3. header += QString("Content-Type: text/plain; charset=ISO-8859-1") + QString("\r\n");
    4. header += QString("Content-Transfer-Encoding: 7bit") + QString("\r\n");
    5. header += QString("Content-Disposition: attachment;") + QString( "filename=" ) + "fileName" + QString("\r\n");
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. HELO there
    2. MAIL FROM : < xyz@gmail.com >
    3. RCPT TO : < abc@yahoo.com >
    4. DATA
    5. Mime-version: 1.0
    6. Content-Type: text/plain; charset=ISO-8859-1
    7. Content-Transfer-Encoding: 7bit
    8. Content-Disposition: attachment; fileName
    9. From: xyz@gmail.com
    10. To: abc@yahoo.com
    11. Subject: Hi..!!!
    12. Hello How are u...???
    13. QUIT
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot and please comment

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SMTP tag for attaching file

    I think you should send a multipart mime type, something like:

    Content-Type: multipart/related; boundary="----------=_marker"; type="text/html"

    < here goes the mail text and headers >

    ------------=_marker
    Content-Type: text/html; charset="iso-8859-2"
    Content-Disposition: attachment; fileName
    MIME-Version: 1.0

    attachment goes here
    ------------=_marker
    Content-Type: text/html; charset="iso-8859-2"
    Content-Disposition: attachment; fileName
    MIME-Version: 1.0

    another attachment goes here
    ------------=_marker

  4. #4
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Post Re: SMTP tag for attaching file

    Hi wysota,
    Thanks for your reply.
    I have a confusion. What is the difference between first solution and your solution???

    I tried your solution, the application says "MESSAGE SENT" but the mail is not received. I did this
    Qt Code:
    1. QString Header;
    2. Header += QString("Content-Type: multipart/related;") +
    3. QString("boundary=--_marker;") +
    4. QString("type=text/html\r\n");
    5.  
    6. QString msgContent;
    7. msgContent += QString("--=_marker\r\n");
    8. msgContent += QString("Content-Type: text/html; charset=ISO-8859-2") + QString("\r\n");
    9. msgContent += QString("Content-Disposition: attachment;") + QString( "filename=" ) + "fileName" + QString("\r\n");
    10. msgContent += QString("Mime-version: 1.0") + QString("\r\n");
    11.  
    12. QString attachmentContent;
    13. attachmentContent += QString("--=_marker\r\n");
    14. attachmentContent += QString("Content-Type: text/html; charset=ISO-8859-2") + QString("\r\n");
    15. attachmentContent += QString("Content-Disposition: attachment;") + QString( "filename=" ) + "fileName" + QString("\r\n");
    16. attachmentContent += QString("Mime-version: 1.0") + QString("\r\n");
    17.  
    18. *t << "DATA\r\n"; //here t is QTextStream
    19. *t << Header;
    20. *t << msgContent;
    21. *t << attachmentContent;
    To copy to clipboard, switch view to plain text mode 
    These contents are sent to SMTP
    Qt Code:
    1. HELO there
    2. MAIL FROM: <xyz@gmail.com>
    3. RCPT TO: <abc@yahoo.com>
    4. DATA
    5. Content-Type: multipart/related;boundary=--_marker;type=text/html
    6. --=_marker
    7. Content-Type: text/html; charset=ISO-8859-2
    8. Content-Disposition: attachment;filename=fileName
    9. Mime-version: 1.0
    10. --=_marker
    11. Content-Type: text/html; charset=ISO-8859-2
    12. Content-Disposition: attachment;filename=fileName
    13. Mime-version: 1.0
    14. From: xyz@gmail.com
    15. To: abc@yahoo.com
    16. Subject: Hi..!!!
    17. Hello How are u...???
    18.  
    19. QUIT
    To copy to clipboard, switch view to plain text mode 

    Any idea???

    One more thing.. why is below code used in the smtp example
    Qt Code:
    1. message.replace( QString::fromLatin1( "\n" ),
    2. QString::fromLatin1( "\r\n" ) );
    3. message.replace( QString::fromLatin1( "\r\n.\r\n" ),
    4. QString::fromLatin1( "\r\n..\r\n" ) );
    To copy to clipboard, switch view to plain text mode 
    If I remove this code the output is still same...
    Thanks
    Last edited by joseph; 6th July 2007 at 05:17.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SMTP tag for attaching file

    1. You didn't set any headers in the main part of the mail.
    2. \r\n is the "network" format of a newline and you should stick with it. Most applications will work without it, but stil...

  6. #6
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Qt Code:
    1. You didn't set any headers in the main part of the mail.
    To copy to clipboard, switch view to plain text mode 
    What header and where to set it?? Can you please add what header and where to set it in the below given example.
    Qt Code:
    1. HELO there
    2. MAIL FROM: <xyz@gmail.com>
    3. RCPT TO: <abc@yahoo.com>
    4. DATA
    5. Content-Type: multipart/related;boundary=--_marker;type=text/html
    6. --=_marker
    7. Content-Type: text/html; charset=ISO-8859-2
    8. Content-Disposition: attachment;filename=fileName
    9. Mime-version: 1.0
    10. --=_marker
    11. Content-Type: text/html; charset=ISO-8859-2
    12. Content-Disposition: attachment;filename=fileName
    13. Mime-version: 1.0
    14. From: xyz@gmail.com
    15. To: abc@yahoo.com
    16. Subject: Hi..!!!
    17. Hello How are u...???
    18.  
    19. QUIT
    To copy to clipboard, switch view to plain text mode 
    Thanks

  7. #7
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Hi wysota,
    Here is what I have been trying...
    Qt Code:
    1. //Message to SMTP
    2. HELO there
    3. MAIL FROM: <xyz@gmail.com>
    4. RCPT TO: <abc@yahoo.com>
    5. DATA
    6. Content-Type: multipart/related; boundary=unique-boundary-1
    7. --unique-boundary-1
    8. Content-Type: text/plain; charset=ISO-8859-1
    9. Content-Transfer-Encoding: 7Bit
    10. Content-Disposition: attachment; filename=fileName
    11. MIME-Version: 1.0
    12. From: xyz@gmail.com
    13. To: abc@yahoo.com
    14. Subject: Hello
    15. How is going?
    16. .
    17. QUIT
    To copy to clipboard, switch view to plain text mode 
    Now i"m able to receive the mail but still there is some problem. The "Subject:" and "To: " part in the mail is empty. There is no information in the "Subject:" and "To:" line.

    Is there anything I'm doing wrong????
    Please help.

  8. #8
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Hi wysota,
    Please help me to solve this.
    There is another problem, I want to encrypt the file and send via mail. I'm able to send the file but unable to open the file again.

    Please help, I'm totally bugged.

    Thanks

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SMTP tag for attaching file

    There has to be an empty line between the last header and the beginning of the body.

    About the encryption - Remember that you can't send characters with ascii numbers larger than 127 via mail. You have to encode them using base64 or uuencode.

    Please read some SMTP specification documents, at least take a look at the RFCs.

  10. #10
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Qt Code:
    1. About the encryption - Remember that you can't send characters with ascii numbers larger than 127 via mail. You have to encode them using base64 or uuencode.
    To copy to clipboard, switch view to plain text mode 
    Hi wysota,
    Now the real problem starts. I have written an function to encrypt and decrypt the file. My target was to send an encrypted file via mail. Now since you tell that "ascii numbers larger than 127 via mail", I have to revert back again.
    I have read about base64, and tried implementing the code. This is the code that I have made use of
    Qt Code:
    1. QString Header;
    2. Header += QString("MIME-Version: 1.0\r\n");
    3. Header += QString("Content-Type: multipart/related; ") + QString("boundary=unique-boundary-1;") + QString( "type=\"text/plain\"\r\n") ;
    4.  
    5. QString headerContent;
    6. headerContent += QString("--unique-boundary-1\r\n");
    7. headerContent += QString("Content-Type: text/plain; charset=iso-8859-2") + QString("\r\n");
    8. headerContent += QString("Content-Transfer-Encoding: base64\r\n");
    9. headerContent += QString("Content-Disposition: attachment;") + QString( "filename=" ) + "fileName" + QString("\r\n");
    To copy to clipboard, switch view to plain text mode 

    Now here starts the problem. Once a mail has been sent, I'm getting some stupid result. Something with only 2 to 3 characters. Any idea why??? Infact the file is big....
    Another doubt is once I'm able to encode the data, hoe do I decode it again.???

    Please tell me at what part of code I need to modify .

    Thanks in advance

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SMTP tag for attaching file

    As far as I remember base64 is implemented in Qt, so you can call a ready made function directly.

  12. #12
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: SMTP tag for attaching file

    Hi wysota,
    There is so much of confusion... I'm using SMTP example from Qtassistant to send mails. As per my thinking, I can specify Content-Transfer-Encoding: base64 to send an encoded data over network. But it doesn't work.

    As per your words-->
    Quote Originally Posted by wysota View Post
    As far as I remember base64 is implemented in Qt, so you can call a ready made function directly.
    Makes me more confuse, as to where I should call the ready made function.??

    Can you please be more clear about what you mean....Thanks

    Is there a better way I can perform this..
    My Requirement-->
    I have an encrypted file encoded with AES::CBC mode with a password. I want to send this encrypted file via mail to others. How can I do that????

    Please help..
    Thanks
    Last edited by joseph; 10th July 2007 at 07:07.

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  4. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  5. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24

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.