LIBETPAN_EXPORT int mailsmtp_send(mailsmtp * session, const char * from, clist * addresses, const char * message, size_t size) { int r; clistiter * l; r = mailsmtp_mail(session, from); if (r != MAILSMTP_NO_ERROR) return r; for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { struct esmtp_address * addr; addr = clist_content(l); r = mailsmtp_rcpt(session, addr->address); if (r != MAILSMTP_NO_ERROR) return r; } r = mailsmtp_data(session); if (r != MAILSMTP_NO_ERROR) return r; r = mailsmtp_data_message(session, message, size); if (r != MAILSMTP_NO_ERROR) return r; return MAILSMTP_NO_ERROR; }
LIBETPAN_EXPORT int mailesmtp_send(mailsmtp * session, const char * from, int return_full, const char * envid, clist * addresses, const char * message, size_t size) { int r; clistiter * l; if (!session->esmtp) return mailsmtp_send(session, from, addresses, message, size); if ((session->esmtp & MAILSMTP_ESMTP_SIZE) != 0) { if (session->smtp_max_msg_size != 0) { if (size > session->smtp_max_msg_size) { return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION; } } } r = mailesmtp_mail_size(session, from, return_full, envid, size); if (r != MAILSMTP_NO_ERROR) return r; for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { struct esmtp_address * addr; addr = clist_content(l); r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt); if (r != MAILSMTP_NO_ERROR) return r; } r = mailsmtp_data(session); if (r != MAILSMTP_NO_ERROR) return r; r = mailsmtp_data_message(session, message, size); if (r != MAILSMTP_NO_ERROR) return r; return MAILSMTP_NO_ERROR; }
int send_message(char *data, size_t len, char**rcpts) { int s = -1; int ret; char **r; int esmtp = 0; mailsmtp *smtp = NULL; if ((smtp = mailsmtp_new(0, NULL)) == NULL) { perror("mailsmtp_new"); goto error; } /* first open the stream */ if ((ret = mailsmtp_socket_connect(smtp, (smtp_server != NULL ? smtp_server : "localhost"), smtp_port)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_socket_connect: %s\n", mailsmtp_strerror(ret)); goto error; } /* then introduce ourselves */ if (smtp_esmtp && (ret = mailesmtp_ehlo(smtp)) == MAILSMTP_NO_ERROR) esmtp = 1; else if (!smtp_esmtp || ret == MAILSMTP_ERROR_NOT_IMPLEMENTED) ret = mailsmtp_helo(smtp); if (ret != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret)); goto error; } if (esmtp && smtp_tls && (ret = mailsmtp_socket_starttls(smtp)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret)); goto error; } if (esmtp && smtp_user != NULL && (ret = mailsmtp_auth(smtp, smtp_user, (smtp_password != NULL) ? smtp_password : "")) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_auth: %s: %s\n", smtp_user, mailsmtp_strerror(ret)); goto error; } /* source */ if ((ret = (esmtp ? mailesmtp_mail(smtp, smtp_from, 1, "etPanSMTPTest") : mailsmtp_mail(smtp, smtp_from))) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_mail: %s, %s\n", smtp_from, mailsmtp_strerror(ret)); goto error; } /* recipients */ for (r = rcpts; *r != NULL; r++) { if ((ret = (esmtp ? mailesmtp_rcpt(smtp, *r, MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY, NULL) : mailsmtp_rcpt(smtp, *r))) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_rcpt: %s: %s\n", *r, mailsmtp_strerror(ret)); goto error; } } /* message */ if ((ret = mailsmtp_data(smtp)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret)); goto error; } if ((ret = mailsmtp_data_message(smtp, data, len)) != MAILSMTP_NO_ERROR) { fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(ret)); goto error; } mailsmtp_free(smtp); return 0; error: if (smtp != NULL) mailsmtp_free(smtp); if (s >= 0) close(s); return -1; }