library/src/network/email/BP-EmailSMTP.cc
// opens a new curl session for the purposes of sending email via SMTP
opens a new curl session for the purposes of sending email via SMTP
opens a new curl session for the purposes of sending email via SMTP
P_BP_EMAIL_SMTP_SESSION BP_OpenSMTPEmailSession(char *username, char *password,	char *smtp_server, size_t smtp_port)
{
	if(!smtp_server || !smtp_port)
		return NULL;
	P_BP_EMAIL_SMTP_SESSION session = NULL;
	session = (P_BP_EMAIL_SMTP_SESSION) bpcalloc(sizeof(BP_EMAIL_SMTP_SESSION), 1);
	if(!session)
		return NULL;
	session->curl = curl_easy_init();
	if(!session->curl)
	{
		bpfree(session);
		return NULL;
	}
	char url_str[8096] = {0};
	snprintf(url_str, 4096, "smtp://%s:%u", smtp_server, smtp_port);
	curl_easy_setopt(session->curl, CURLOPT_URL, url_str);
	if(username)
	 	curl_easy_setopt(session->curl, CURLOPT_USERNAME, username);
    if(password)
    	curl_easy_setopt(session->curl, CURLOPT_PASSWORD, password);
    curl_easy_setopt(session->curl, CURLOPT_USE_SSL, (long) CURLUSESSL_TRY);
    curl_easy_setopt(session->curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(session->curl, CURLOPT_SSL_VERIFYHOST, 0L);
    curl_easy_setopt(session->curl, CURLOPT_READFUNCTION, payload_source);
	return session;
}
P_BP_EMAIL_SMTP_SESSION BP_OpenSMTPEmailSession ( char * username , char * password , char * smtp_server , size_t smtp_port ) { if ( ! smtp_server || ! smtp_port ) return NULL ; P_BP_EMAIL_SMTP_SESSION session = NULL ; session = ( P_BP_EMAIL_SMTP_SESSION ) bpcalloc ( sizeof ( BP_EMAIL_SMTP_SESSION ) , 1 ) ; if ( ! session ) return NULL ; session -> curl = curl_easy_init ( ) ; if ( ! session -> curl ) { bpfree ( session ) ; return NULL ; } char url_str [ 8096 ] = { 0 } ; snprintf ( url_str , 4096 , " " , smtp_server , smtp_port ) ; curl_easy_setopt ( session -> curl , CURLOPT_URL , url_str ) ; if ( username ) curl_easy_setopt ( session -> curl , CURLOPT_USERNAME , username ) ; if ( password ) curl_easy_setopt ( session -> curl , CURLOPT_PASSWORD , password ) ; curl_easy_setopt ( session -> curl , CURLOPT_USE_SSL , ( long ) CURLUSESSL_TRY ) ; curl_easy_setopt ( session -> curl , CURLOPT_SSL_VERIFYPEER , 0L ) ; curl_easy_setopt ( session -> curl , CURLOPT_SSL_VERIFYHOST , 0L ) ; curl_easy_setopt ( session -> curl , CURLOPT_READFUNCTION , payload_source ) ; return session ; }
opens a new curl session for the purposes of sending email via SMTP
opens a new curl session for the purposes of sending email via SMTP
// check for server and port // session pointer (returned) // allocate space for the session // create new curl object // create buffer to store url composite // create the connect string // ######################################################### // ### Set CURL Parameters ################################# // ######################################################### // set the url string // set username and password in curl structure // set tlsv123 as default ssl data // set ssl verification policy // set the read function // return session