Send a simple email message with one attachment
This short function sends a simple email with one attachment to one recipient (without the result callback) from the default email account on the device. PRIVILEGES NEEDED to be set in tizen-manifest.xml: http://tizen.org/privilege/email http://tizen.org/privilege/mediastorage
// PRIVILEGES NEEDED to be set in tizen-manifest.xml file:
// to access email service:
// http://tizen.org/privilege/email
// to access phone storage from which a file to be attached is taken:
// http://tizen.org/privilege/mediastorage
#include <email.h>
#include <dlog.h> // for logging purposes
bool send_simple_email(const char *recipient, const char *subject, const char *body, const char *attachment_path)
{
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_add_attach(mail, attachment_path)!= EMAILS_ERROR_NONE)
{
dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding an attachment 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;
}