Send a simple email message
This short function sends a simple email message to one recipient (without sending result callback) from the default email account on the device.
At least one email account must be already configured on the device.
PRIVILEGE NEEDED to be set in tizen-manifest.xml: http://tizen.org/privilege/email
// PRIVILEGE NEEDED to be set in tizen-manifest.xml file:
// http://tizen.org/privilege/email
#include <email.h>
#include <dlog.h> // for logging purposes
bool send_simple_email(const char *recipient, const char *subject, const char *body)
{
email_h mail;
if (email_create_message(&mail)!= EMAILS_ERROR_NONE)
{
dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when creating email message!");
return false;
}
if ((email_add_recipient(mail, EMAIL_RECIPIENT_TYPE_TO, recipient)!= EMAILS_ERROR_NONE)
|| (email_set_subject(mail, subject) != EMAILS_ERROR_NONE)
|| (email_set_body(mail, body) != EMAILS_ERROR_NONE))
{
dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding data to email message!");
email_destroy_message(mail);
return false;
}
if (email_save_message(mail) != EMAILS_ERROR_NONE
||email_send_message(mail, false) != EMAILS_ERROR_NONE)
{
dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when sending message!");
email_destroy_message(mail);
return false;
}
else
{
dlog_print(DLOG_INFO, LOG_TAG, "Sending message...");
}
if (email_destroy_message(mail) == EMAILS_ERROR_NONE)
{
dlog_print(DLOG_INFO, LOG_TAG, "Successfully released memory allocated for the message.");
}
return true;
}