Overview
Features
Download
Documentation
Community
Add-Ons & Services

Sending e-mail on OSX.

Please post support and help requests here.

Sending e-mail on OSX.

Postby mattcox » 29 Jun 2012, 15:39

Hi.

I recently wrote an application on windows using the Poco library. I'm porting it over to OSX and Linux at the moment.

I'm having trouble getting some code to run on OSX for sending e-mails.
Code: Select all
int sendEmail_message (string inputTo, string inputSubject, string inputMessage)
{   
   SSLInitializer   sslInitializer;

   string mailhost   = "smtp.gmail.com";
   string sender = "email@gmail.com";
   string recipient = inputTo;
   
   try
   {
      SharedPtr<InvalidCertificateHandler> pCert = new AcceptCertificateHandler(false);
      Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
      SSLManager::instance().initializeClient(0, pCert, pContext);

      MailMessage message;
      message.setSender(sender);
      message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));
      message.setSubject(inputSubject);
      std::string content;
      content += inputMessage;
      message.addContent(new StringPartSource(content));
     
      SecureSMTPClientSession session(mailhost);
      session.login();
      session.startTLS(pContext);
      session.login(SMTPClientSession::AUTH_LOGIN, "email@gmail.com", "password");
      session.sendMessage(message);
      session.close();
      return 0;
   }
   catch (Exception& exc)
   {
      cerr << padding << exc.displayText() << endl;
      return 1;
   }
}

The code above runs fine on windows and sends e-mails. But if I attempt to run it on OSX, It hangs for a while and then writes out "timeout".

Everything is building ok on OSX, it just times out at run time. As far as I can tell, it's hanging on the line:
Code: Select all
SecureSMTPClientSession session(mailhost);


Is there anything anyone can suggest to help me track down what the problem is? It would be ok if I had some more information as to what is happening or a way to output a log of the connection. I'm pretty new to OSX development, so I might be missing something obvious.

-Matt
mattcox
 
Posts: 7
Joined: 08 May 2012, 21:46

Re: Sending e-mail on OSX.

Postby alex » 30 Jun 2012, 01:17

which version of POCO?
alex
 
Posts: 1114
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Sending e-mail on OSX.

Postby mattcox » 30 Jun 2012, 02:26

1.4.3p1.

-Matt
mattcox
 
Posts: 7
Joined: 08 May 2012, 21:46

Re: Sending e-mail on OSX.

Postby alex » 03 Jul 2012, 04:24

I could not reproduce your problem, it works fine for me:

Code: Select all
alex$ uname -pv
Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 i386
alex$ pwd
/Users/alex/Documents/Projects/poco/poco-1.4.3/NetSSL_OpenSSL/samples/Mail/bin/Darwin/x86_64
alex$ ./Mail smtp.gmail.com email@gmail.com email@gmail.com email@gmail.com password

WARNING: Certificate verification failed
----------------------------------------
Issuer Name:  /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Subject Name: /C=US/O=Google Inc/CN=Google Internet Authority

The certificate yielded the error: unable to get local issuer certificate

The error occurred in the certificate chain at position 1
Accept the certificate (y,n)? y

WARNING: Certificate verification failed
----------------------------------------
Issuer Name:  /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Subject Name: /C=US/O=Google Inc/CN=Google Internet Authority

The certificate yielded the error: certificate not trusted

The error occurred in the certificate chain at position 1
Accept the certificate (y,n)? y


and mail is sent.
alex
 
Posts: 1114
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Sending e-mail on OSX.

Postby mattcox » 03 Jul 2012, 18:07

Hi Alex,

Thanks for the reply.

I just tried exactly the same thing, using the sample provided and all it does here is sit there for about a minute and then it says "Timeout".

I've tried updating OpenSSL, but that made no difference.

-Matt
mattcox
 
Posts: 7
Joined: 08 May 2012, 21:46


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron