0

I'm trying to use the libetpan library and the code below to send email through Google servers. However, when I run mailsmtp_auth it returns 16 (MAILSMTP_ERROR_AUTH_NOT_SUPPORTED). Any ideas why? I've got IMAP running great using the same library, but the SMTP is eluding me for some reason. I've found many samples online, but none of them seem to work for Gmail.

int ret;
mailsmtp *smtp = NULL;
mailstream_low * low;
int fd;
mailstream_low * new_low;
char smtp_server[100] = "smtp.gmail.com";
char smtp_user[100] = "user";
char smtp_pass[100] = "password";
char smtp_email[100] = "user@gmail.com";
char body[100] = "Test email";


if ( (smtp = mailsmtp_new(0,NULL)) == NULL ){
    return FALSE;
}
if ( (ret = mailsmtp_socket_connect(smtp, smtp_server, 587) != MAILSMTP_NO_ERROR ) ){
    fprintf(stderr, "mail_socket_connect: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
ret = mailesmtp_ehlo(smtp);
if (ret != MAIL_NO_ERROR) {
    fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
ret = mailesmtp_starttls(smtp);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
// THIS IS WHERE THE ERROR OCCURS
ret = mailsmtp_auth(smtp, smtp_user, smtp_pass);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_auth: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
ret = mailsmtp_mail(smtp, smtp_email);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_mail: %s\n",mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
    ret = mailsmtp_rcpt(smtp, smtp_email);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_rcpt: %s\n",mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
} 
ret = mailsmtp_data(smtp);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
ret = mailsmtp_data_message(smtp, body, strlen(body));
if (ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_data_meassage: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
return TRUE;

--------------------------------------

[EDIT #1]: SASL

--------------------------------------

I have managed to get this to ALMOST work by editing the source of libetpan and fixing some issues with Win32 in it's code base (I will post the results once I get it 100% working). However, Gmail appears to require SASL. There is no documentation for including SASL support in libetpan when compiling in windows (Visual Studio 2010), and I'm having a lot of trouble locating any information online that is Windows specific.

What would the easiest way to get SASL in be? Is there a precompiled/prebuilt windows SASL .lib file that I can use standard sasl.h files with?

Thanks, Ben

Fmstrat
  • 1,492
  • 2
  • 17
  • 24

1 Answers1

0

Try calling mailsmtp_init first then calling mailesmtp_ehlo after mailesmtp_starttls like this:

if ( (ret = mailsmtp_ssl_connect(smtp, smtp_server, 587 ) != MAILSMTP_NO_ERROR ) ){
    fprintf(stderr, "mail_ssl_connect: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}

ret = mailsmtp_init(smtp );
if (ret != MAILSMTP_NO_ERROR) {
    fprintf(stderr, "mailsmtp_init: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}

ret = mailesmtp_starttls(smtp);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}

ret = mailesmtp_ehlo(smtp);
if (ret != MAIL_NO_ERROR) {
    fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}

ret = mailsmtp_auth(smtp, smtp_user, smtp_pass);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_auth: %s\n", mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}

ret = mailsmtp_mail(smtp, smtp_email);
if ( ret != MAIL_NO_ERROR ) {
    fprintf(stderr, "mailsmtp_mail: %s\n",mailsmtp_strerror(ret) );
    mailsmtp_free(smtp);
    return FALSE;
}
Michael Minton
  • 4,447
  • 2
  • 19
  • 31
  • Thanks for the response. I tried this, but now get a MAILSMTP_ERROR_STREAM (3) on mailesmtp_ehlo command. – Fmstrat Nov 10 '12 at 01:31
  • I also tried some code I found online, that had " low = mailstream_get_low(smtp->stream); fd = mailstream_low_get_fd(low); new_low = mailstream_low_tls_open(fd); mailstream_low_free(low); mailstream_set_low(smtp->stream, new_low);" before the "ehlo", but that just caused the mailesmtp_ehlo command to crash the app. That sample also had ehlo first, instead of helo. – Fmstrat Nov 10 '12 at 01:33
  • Actually, I just realized you changed "socket" to "ssl" in the connect. Using "ssl", the libetpan library actually crashes out.. – Fmstrat Nov 10 '12 at 01:44