Results 1 to 20 of 36

Thread: Sending email using Qt.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    2
    Thanked 6 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending email using Qt.

    Quote Originally Posted by blue.death
    Hi guys,

    I am working on a SMTP client too and I do quite the same things as in the Qt example (btw. I didnt remember there was such an example ).
    The problem is my app won't connect if I don't call waitForConnected()!

    But isnt this method useless if we wand non-blocking sockets?
    Other code examples simply call connectToHost(...) after setting up the right connections.
    If I don't call waitForConnected() the socket status remains on LookingUpHost (or whatever the exact name is)

    Any clue???

    The example was only in the QT 3.x series under networking examples, i just altered it to work in QT 4.x.

    My understanding of the "waitForConnected()" function is that it's simply a delay to allow a handshake to occur, it doesn't actually do anything unless you want to establish a timeout (lets say for a server that's offline) and take the bool return to do error correction.

    Basically it is a delay before completing the socket.

    I removed the "waitForConnected()" from my client and it established a connection immediately, but my mail server is also on the company lan and connects extremely quickly.

    Using the "waitForConnected()" function should have no effect on how you connect unless you choose to implement error correction based on it's return.

    If you don't want to use it then i suggest putting a delay in, something like 10-15 seconds, which is close to a worst case connection delay for most internet applications.

    Of course if you use "waitForConnected(15000)" then it will automatically stop the delay after either 15 seconds (a timeout) or you establish a connection (if it's less than the passed 15 seconds), which would make sense to minimize the time your application is waiting.

    J

  2. The following user says thank you to nielsenj for this useful post:

    marcovictor (8th October 2010)

  3. #2
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sending email using Qt.

    Even this Post is old, it was very usefull for me. So a big thank you!!
    But i have to notes for using MS Exchange Server (in my case Version 2000).
    You have to change two things inside the code:
    1. Don´t remove
      Qt Code:
      1. if (smtpsocket->waitForConnected(Timeout))
      To copy to clipboard, switch view to plain text mode 
      or no mails will be send. Instead decrease the timeout, i.e. 500.
    2. In function "PutSendLine()", in step "case 4"
      replace the response "ok" with "Authentication successful" because this is the real responce and it wont work else.

  4. The following 3 users say thank you to pinktroll for this useful post:

    codeslicer (12th February 2008), lllturtle (16th August 2011), mchrk (19th December 2008)

  5. #3

    Default Re: Sending email using Qt.

    Hello,
    I'm newbie and I'd like to understand correctly this code.
    Could you write what is the "output" is it sth. like stdout?:

    Qt Code:
    1. void Smtp::connected()
    2. {
    3. output->append("connected");
    4. qDebug() << "Connected ";
    5. }
    To copy to clipboard, switch view to plain text mode 

    thanks
    Last edited by Ryczypisk; 4th November 2009 at 13:00.

  6. #4
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending email using Qt.

    I used the structure from the post #9, taking into account post #11 (especially the second note). I am successfully connecting to the server and sending it those "lines" until it comes to send line number 7 (function PutSendLine(), case 7) - it's an actual message. After this line:
    Qt Code:
    1. response = SendLineAndGrab(message+"\r\n.");
    To copy to clipboard, switch view to plain text mode 
    I'm receiving such a response from a server:
    "550 5.5.2 Unknown command 'Date: Mon, 8 Mar 2010 15:54:26'
    I have tried to remove the date (by commenting one of the first lines in smtp.cpp), but then I received similar response but this time it was aobut "User-Agent: Mozilla Thunderbird 1.0.6...".

    Why is the server sending such responses? How to make it work?

  7. #5
    Join Date
    Mar 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Sending email using Qt.

    in step 5
    SendLineAndGrab("MAIL FROM: "+from);
    someserver return:
    501 Bad address syntax
    so this line must chang to:
    SendLineAndGrab("MAIL FROM:<"+from+">");

  8. #6

    Default Re: Sending email using Qt.

    How can we add to this code an option to send attached files?

  9. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sending email using Qt.

    7-bit encode the attachments using something like Base64 and then attach them to the body of the email as a MIME attachment making sure that the message and each attachment has a different id so that the receiving email client knows how to seperate the parts again.

  10. #8
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending email using Qt.

    See POCO Libraries, its very helpfull
    http://pocoproject.org

  11. #9
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending email using Qt.

    thank you very much

  12. #10
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Smile Re: Sending email using Qt.

    Can someone post some working code please? It'd be much appreciated and save the rest of us a lot of time and effort.
    Sure, we could dig at this for a few days and get it to eventually work -- but why climb a mountain when someone's already built an escalator?

    Cheers in advance

  13. #11

    Default Re: Sending email using Qt.

    Quote Originally Posted by fatjuicymole View Post
    7-bit encode the attachments using something like Base64 and then attach them to the body of the email as a MIME attachment making sure that the message and each attachment has a different id so that the receiving email client knows how to seperate the parts again.
    My mayor problem is that i receive an empty file if i do that, i must be doing something wrong

Similar Threads

  1. Replies: 9
    Last Post: 23rd August 2012, 00:01
  2. Replies: 7
    Last Post: 5th January 2009, 08:27
  3. Sending Mail through QProcess
    By KaptainKarl in forum Qt Programming
    Replies: 6
    Last Post: 13th August 2008, 21:51
  4. sending encrypted data via mail using smtp
    By vermarajeev in forum General Programming
    Replies: 20
    Last Post: 14th August 2007, 19:47
  5. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23

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
  •  
Qt is a trademark of The Qt Company.