summaryrefslogtreecommitdiff
path: root/src/mail.cpp
blob: 84e121062ca470bec071a6e3b8c1f204b42c2742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "mail.hpp"

#include <iostream>

mailer::mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from )
	: server( server ), port( port ), username( username ), password( password ), from( from )
{
	quickmail_initialize( );
	mailobj = quickmail_create( NULL, NULL );
}

mailer::~mailer( )
{
	quickmail_destroy( mailobj );
}

void mailer::send( )
{
	if( !from.empty( ) ) {
		quickmail_set_from( mailobj, from.c_str( ) );
	}

	if( !to.empty( ) ) {
		quickmail_add_to( mailobj, to.c_str( ) );
	}

	if( !subject.empty( ) ) {
		quickmail_set_subject( mailobj, subject.c_str( ) );
	}

	if( !body.empty( ) ) {
		quickmail_add_body_memory( mailobj, "plain/text", const_cast<char *>( body.c_str( ) ), body.size( ), 0 );
	}

    const char *errmsg;
    errmsg = quickmail_send( mailobj, server.c_str( ), port, username.c_str( ), password.c_str( ) );
    std::cerr << "ERROR: " << errmsg << std::endl;
}