Results 1 to 13 of 13

Thread: connect to smtp gmail server

  1. #1
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default connect to smtp gmail server

    Hi,
    I am trying to send an email using gmail or yahoo ..etc.
    I was looking into this thread
    The issue i am facing is, when i try to connect to smtp.gmail.com, the connection fails. and the HostNotFoundError is thrown.

    The smtp server name for gmail i got it from this website, here it says that

    server address :smtp.gmail.com
    port : 465
    TLS/SSL required: yes, which i did not understand, what exactly i have to do for this case.

    The code i am using is the code written by patrik08 in this thread post #9, I also made the edit that was mentioned in post #11.

    so right now,I'm not able to get the connection to be successful.
    Qt Code:
    1. connect(smtpSocket,SIGNAL(connected()),this,SLOT(smtpConnected()))
    2. connect(smtpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(smtpError(QAbstractSocket::SocketError)))
    3. ....
    4. ....
    5. smtpSocket->connectToHost("smtp.gmail.com",465) // I also tried port 25 as in the original code but it failes to.
    To copy to clipboard, switch view to plain text mode 
    Please if any one can help me with this I would really appreciate it.

    BTW: the reason for making new thread, because i asked there and no one reply, as the thread really old and has too many replies so it seems no one is interested to reply , as well it maybe i am asking a noob questions, so I though maybe someone here will be welling to help me.


    I made a compiled version with GUI interface to use the SMTP class{Send_Email.tar.gz}, so if anyone would like to test and try it.

    Thanks

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

    Default Re: connect to smtp gmail server

    The error message is descriptive of the problem: your machine cannot resolve the DNS name "smtp.gmail.com" into an IP address. This may be a transient error in your DNS service or it may be because you are behind a proxy. Either way, Qt is simply reporting what the operating system is telling it.

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

    IwantToLearen (14th February 2013)

  4. #3
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Thanks for explaining to me the reason, Yeah i do I am connected using a proxy, so how can I achieve this ? which is sending an email while i am using proxy ? is it possible ?


    Thanks

  5. #4
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    use QNetworkProxy
    http://doc.qt.io/qt-4.8/QNetworkProxy
    then smtpsocket->setProxy(your_ QNetworkProxy)

  6. The following user says thank you to alrawab for this useful post:

    IwantToLearen (14th February 2013)

  7. #5
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Thanks,
    I used the QNetworkProxy, and now the error message changed to "SocketTimeoutError".

  8. #6
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Quote Originally Posted by IwantToLearen View Post
    Thanks,
    I used the QNetworkProxy, and now the error message changed to "SocketTimeoutError".
    https://github.com/bluetiger9/SmtpClient-for-Qt

  9. The following user says thank you to alrawab for this useful post:

    IwantToLearen (14th February 2013)

  10. #7
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Thank you so much,
    Yeah i found this code and I was using it as well, i added a proxy to it.
    I still get time out error.
    I print out the status and the error, and i get this:

    statechanged :: QAbstractSocket::HostLookupState
    statechanged :: QAbstractSocket::ConnectingState
    statechanged :: QAbstractSocket::UnconnectedState
    socketError :: QAbstractSocket::SocketTimeoutError
    statechanged :: QAbstractSocket::UnconnectedState

    I will try this with other internet connection, where i do not need to use proxy and I see what will i get.

  11. #8
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server


  12. #9
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Looking into the link you gave me, its says gmail uses 465 for SSL and 587 for TLS, and the code uses QSslSocket. they also say try using 25 for SSL as well.

    I tried all the ports possible, still get the timeout error.

    As reading on other post, Squidge on reply #5 was saying

    'Read Timeout' sounds to me like a successfull connect, but a failed negotiation (ie, waiting for something that didn't appear in a suitable time frame)
    After Tottish showed a wireshark results for the time out erro, and Wysota on reply #7, as the time out happen because of waiting for SSL handshake and it fails.

    but I though the QSslSocket is for a SSL connection and will do the SSL handshake.

  13. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,625
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: connect to smtp gmail server

    On Windows you need the OpenSSL DLL available to the program. If that is your platform absence of the runtime library may be your problem.

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

    IwantToLearen (18th February 2013)

  15. #11
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    dude don't try to reinvent the wheel as I mentioned before this class is perfect and deal with different types of sockets
    https://github.com/bluetiger9/SmtpClient-for-Qt
    move src Dir to your project and right click ==>add Existing Files (choose src )
    now if you use windows you have to get openSSL runtime (@ChrisW67 #10)
    http://slproweb.com/download/Win32Op...ght-1_0_0k.exe
    put libeay32.dll,libssl32.dll and ssleay32.dll whrer QtNetwork4.dll (or add them to your enviroment path)
    for proxy :
    QNetworkProxy proxy(QNetworkProxy::HttpProxy,_change_it_your_pro xy,_change_it_proxy_port,_change_it_user,_change_i t_password);
    socket->setProxy(proxy);
    Good Luck
    16-02-2013 06-49-49 ص.jpg
    Last edited by alrawab; 16th February 2013 at 07:52.

  16. The following user says thank you to alrawab for this useful post:

    IwantToLearen (18th February 2013)

  17. #12
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect to smtp gmail server

    Thanks for your replying and help.

    I am really not trying to reinvent the wheel. I am using the SmtpClient-for-Qt and i added the set proxy method as well. I am not working on windows I am working on Linux/ redhat.
    as I see in the screen shot you attached, that you sent an email using it successfully, did you used proxy or not ??

    Thanks.

  18. #13

    Default Re: connect to smtp gmail server

    I spent ages trying to communicate with GMails SMTP server over a non proxied connection. It was only when I tried SSL over port 25 that I had any joy, I couldn't get anything back using TSL at all.. If it's an option try port 25 SSL without the proxy and then when that's working try adding the proxy code.

Similar Threads

  1. Connect To Sql Server With QT
    By METEOR7 in forum Qt Programming
    Replies: 6
    Last Post: 13th December 2011, 12:39
  2. Replies: 9
    Last Post: 2nd March 2011, 11:58
  3. Trying to Connect To SQL Server 2005
    By rossd in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2009, 19:56
  4. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  5. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06

Tags for this Thread

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.