/// <summary> /// The constructor. /// </summary> /// <since_tizen> 3 </since_tizen> public EmailMessage() { int ret = Interop.Email.CreateEmail(out _emailHandle); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to create message handle, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } }
internal void Save() { int ret; FillHandle(); ret = Interop.Email.SaveEmail(_emailHandle); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to save email, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } }
internal void FillHandle() { int ret = (int)EmailError.None; foreach (EmailAttachment it in Attachments) { Console.WriteLine(it.FilePath); ret = Interop.Email.AddAttachment(_emailHandle, it.FilePath); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to add attachment, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } } foreach (EmailRecipient it in To) { ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.To, it.Address); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } } foreach (EmailRecipient it in Cc) { ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Cc, it.Address); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } } foreach (EmailRecipient it in Bcc) { ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Bcc, it.Address); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } } }
/// <summary> /// Sends the email message. /// </summary> /// <param name="email">The email message.</param> /// <returns> Failure if the email sending activity failed, otherwise Success.</returns> /// <since_tizen> 3 </since_tizen> public static async Task <EmailSendResult> SendAsync(EmailMessage email) { var task = new TaskCompletionSource <EmailSendResult>(); int ret = (int)EmailError.None; bool saveToSentBox = false; email.FillHandle(); email.Save(); int id = _callbackId++; _sendCbMap[id] = (IntPtr handle, int result, IntPtr userData) => { task?.SetResult((EmailSendResult)result); _sendCbMap.Remove((int)userData); }; ret = Interop.Email.SetCb(email._emailHandle, _sendCbMap[id], (IntPtr)id); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); _sendCbMap.Remove(id); throw EmailErrorFactory.GetException(ret); } ret = Interop.Email.SendEmail(email._emailHandle, saveToSentBox); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to send email, Error code: " + (EmailError)ret); _sendCbMap.Remove(id); throw EmailErrorFactory.GetException(ret); } var sendResult = await task.Task.ConfigureAwait(false); ret = Interop.Email.UnsetCb(email._emailHandle); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } return(sendResult); }
/// <summary> /// Sends the email message. /// </summary> /// <param name="email">The email message.</param> /// <returns> Failure if the email sending activity failed, otherwise Success.</returns> /// <since_tizen> 3 </since_tizen> public static async Task <EmailSendResult> SendAsync(EmailMessage email) { var task = new TaskCompletionSource <EmailSendResult>(); int ret = (int)EmailError.None; bool saveToSentBox = false; email.FillHandle(); email.Save(); Interop.Email.EmailSentCallback _emailSendingCallback = (IntPtr handle, int result, IntPtr userData) => { task.SetResult((EmailSendResult)result); }; ret = Interop.Email.SetCb(email._emailHandle, _emailSendingCallback, IntPtr.Zero); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } ret = Interop.Email.SendEmail(email._emailHandle, saveToSentBox); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to send email, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } var sendResult = await task.Task; ret = Interop.Email.UnsetCb(email._emailHandle); if (ret != (int)EmailError.None) { Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); throw EmailErrorFactory.GetException(ret); } return(sendResult); }