int smtpsend(char *server, unsigned short port, char *user, char *password, char *from, char **recipients, int security, BOOL no_esmtp, int email) { struct mem_message message; int ret; #ifdef _DEBUG mailstream_debug=1; #endif if (smtp_server != NULL) free(smtp_server); smtp_server = _strdup(server); smtp_port = port; if (smtp_user != NULL) free(smtp_user); smtp_user = _strdup(user); if (smtp_password != NULL) free(smtp_password); smtp_password = _strdup(password); if (smtp_from != NULL) free(smtp_from); smtp_from = _strdup(from); if(security == SECURITY_TLS) smtp_tls = 1; else smtp_tls = 0; if(security == SECURITY_SSL) smtp_ssl = 1; else smtp_ssl = 0; if(no_esmtp) smtp_esmtp = 0; else smtp_esmtp = 1; if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) { fprintf(stderr, "can't guess a valid from, please use -f option.\n"); return EXIT_FAILURE; } // reads message from stdin if (collect(&message, email)) return EXIT_FAILURE; ret = send_message(message.data, message.len, recipients); release(&message); return ret; }
int main(int argc, char **argv) { struct mem_message message; int indx, r; static struct option long_options[] = { {"server", 1, 0, 's'}, {"port", 1, 0, 'p'}, {"user", 1, 0, 'u'}, {"password", 1, 0, 'v'}, {"from", 1, 0, 'f'}, {"tls", 0, 0, 'S'}, {"no-esmtp", 0, 0, 'E'}, }; while(1) { if ((r = getopt_long(argc, argv, "s:p:u:v:f:SE", long_options, &indx)) < 0) break; switch (r) { case 's': if (smtp_server != NULL) free(smtp_server); smtp_server = strdup(optarg); break; case 'p': smtp_port = (uint16_t) strtoul(optarg, NULL, 10); break; case 'u': if (smtp_user != NULL) free(smtp_user); smtp_user = strdup(optarg); break; case 'v': if (smtp_password != NULL) free(smtp_password); smtp_password = strdup(optarg); break; case 'f': if (smtp_from != NULL) free(smtp_from); smtp_from = strdup(optarg); break; case 'S': smtp_tls = 1; break; case 'E': smtp_esmtp = 0; break; } } argc -= optind; argv += optind; if (argc < 1) { fprintf(stderr, "usage: smtpsend [-f from] [-u user] [-v password] [-s server] [-p port] [-S] <rcpts>...\n"); return EXIT_FAILURE; } if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) { fprintf(stderr, "can't guess a valid from, please use -f option.\n"); return EXIT_FAILURE; } /* reads message from stdin */ if (collect(&message)) return EXIT_FAILURE; send_message(message.data, message.len, argv); release(&message); return EXIT_SUCCESS; }