示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }