Re: mailsmtp_auth_sasl instead of mailsmtp_auth
DINH Viêt Hoà <[email protected]> Wed, 21 Jun 2006 01:18:17 +0200
| Newsgroups | gmane.mail.libetpan.user |
|---|---|
| Message-ID | <[email protected]> |
On 20 Jun 2006, at 08:17, Matt Ronge wrote: > Hi, > > I've been using mailsmtp_auth but I've recently run into a problem > where > it wasn't working on a gmail SMTP server. After taking a look at > mailsmtp.h I noticed that mailsmtp_auth is now deprecated. > > Here's the new function: > int mailesmtp_auth_sasl(mailsmtp * session, const char * auth_type, > const char * server_fqdn, > const char * local_ip_port, > const char * remote_ip_port, > const char * login, const char * auth_name, > const char * password, const char * realm); > > However, I'm not sure how to get started with it. Is there any > documentation for this? What are the available auth_type's? What is > the > server_fqdn? What about the local port? Auth_name? realm? Does anyone > have an example of this function in use? > > (Please point me to the appropriate RFC if I'm missing something) > Thanks, on google smtp, you need to start tls before authenticating. I attached a code that I tested with my account. This code worked for google smtp. -- DINH Viêt Hoà _______________________________________________ Libetpan-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libetpan-users
smtptest.c
(application/octet-stream, 2.9 KB)
#include <libetpan/libetpan.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
static int fill_remote_ip_port(mailstream * stream, char * remote_ip_port,
size_t remote_ip_port_len)
{
mailstream_low * low;
int fd;
struct sockaddr_in name;
socklen_t namelen;
char remote_ip_port_buf[128];
int r;
low = mailstream_get_low(stream);
fd = mailstream_low_get_fd(low);
namelen = sizeof(name);
r = getpeername(fd, (struct sockaddr *) &name, &namelen);
if (r < 0)
return -1;
if (inet_ntop(AF_INET, &name.sin_addr, remote_ip_port_buf,
sizeof(remote_ip_port_buf)))
return -1;
snprintf(remote_ip_port, remote_ip_port_len, "%s;%i",
remote_ip_port_buf, ntohs(name.sin_port));
return 0;
}
static int fill_local_ip_port(mailstream * stream, char * local_ip_port,
size_t local_ip_port_len)
{
mailstream_low * low;
int fd;
struct sockaddr_in name;
socklen_t namelen;
char local_ip_port_buf[128];
int r;
low = mailstream_get_low(stream);
fd = mailstream_low_get_fd(low);
namelen = sizeof(name);
r = getpeername(fd, (struct sockaddr *) &name, &namelen);
if (r < 0)
return -1;
if (inet_ntop(AF_INET, &name.sin_addr, local_ip_port_buf,
sizeof(local_ip_port_buf)))
return -1;
snprintf(local_ip_port, local_ip_port_len, "%s;%i",
local_ip_port_buf, ntohs(name.sin_port));
return 0;
}
int main(void)
{
mailsmtp * smtp;
mailstream_low * low;
int fd;
mailstream_low * new_low;
char local_ip_port_buf[128];
char remote_ip_port_buf[128];
char * local_ip_port;
char * remote_ip_port;
int r;
mailstream_debug = 1;
smtp = mailsmtp_new(0, NULL);
/* check error */
mailsmtp_socket_connect(smtp, "smtp.gmail.com", 25);
/* check error */
mailesmtp_ehlo(smtp);
/* check error */
mailesmtp_starttls(smtp);
/* check error */
low = mailstream_get_low(smtp->stream);
fd = mailstream_low_get_fd(low);
new_low = mailstream_low_tls_open(fd);
/* check error */
mailstream_low_free(low);
mailstream_set_low(smtp->stream, new_low);
mailesmtp_ehlo(smtp);
/* check error */
r = fill_local_ip_port(smtp->stream, local_ip_port_buf,
sizeof(local_ip_port_buf));
if (r < 0)
local_ip_port = NULL;
else
local_ip_port = local_ip_port_buf;
r = fill_remote_ip_port(smtp->stream, remote_ip_port_buf,
sizeof(remote_ip_port_buf));
if (r < 0)
remote_ip_port = NULL;
else
remote_ip_port = remote_ip_port_buf;
r = mailesmtp_auth_sasl(smtp, "PLAIN",
"smtp.gmail.com",
local_ip_port, remote_ip_port,
"[email protected]", "[email protected]",
"password", "smtp.gmail.com");
/*
in most case, login = auth_name = user@domain
and realm = server hostname full qualified domain name
*/
/* check error */
return 0;
}