2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
21 namespace Tizen.Messaging.Email
24 /// This class contains the Messaging API to support sending email messages.
26 /// <since_tizen> 3 </since_tizen>
27 [Obsolete("Deprecated since API11. Might be removed in API13")]
28 public class EmailMessage : IDisposable
30 internal IntPtr _emailHandle = IntPtr.Zero;
31 private bool _disposed = false;
32 private String _subject;
34 private IList<EmailAttachment> _attachments = new List<EmailAttachment>();
35 private ICollection<EmailRecipient> _to = new Collection<EmailRecipient>();
36 private ICollection<EmailRecipient> _cc = new Collection<EmailRecipient>();
37 private ICollection<EmailRecipient> _bcc = new Collection<EmailRecipient>();
42 /// <since_tizen> 3 </since_tizen>
43 [Obsolete("Deprecated since API11. Might be removed in API13")]
46 int ret = Interop.Email.CreateEmail(out _emailHandle);
47 if (ret != (int)EmailError.None)
49 Log.Error(EmailErrorFactory.LogTag, "Failed to create message handle, Error code: " + (EmailError)ret);
50 throw EmailErrorFactory.GetException(ret);
55 /// The subject of the email message.
57 /// <since_tizen> 3 </since_tizen>
58 [Obsolete("Deprecated since API11. Might be removed in API13")]
64 int ret = Interop.Email.SetSubject(_emailHandle, _subject);
65 if (ret != (int)EmailError.None)
67 Log.Error(EmailErrorFactory.LogTag, "Failed to set subject, Error code: " + (EmailError)ret);
68 throw EmailErrorFactory.GetException(ret);
79 /// The body of the email message.
81 /// <since_tizen> 3 </since_tizen>
82 [Obsolete("Deprecated since API11. Might be removed in API13")]
88 int ret = Interop.Email.SetBody(_emailHandle, _body);
89 if (ret != (int)EmailError.None)
91 Log.Error(EmailErrorFactory.LogTag, "Failed to set body, Error code: " + (EmailError)ret);
92 throw EmailErrorFactory.GetException(ret);
102 /// The list of file attachments.
104 /// <since_tizen> 3 </since_tizen>
105 [Obsolete("Deprecated since API11. Might be removed in API13")]
106 public IList<EmailAttachment> Attachments
115 /// The collection of normal email recipients.
118 /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
120 /// <since_tizen> 3 </since_tizen>
121 [Obsolete("Deprecated since API11. Might be removed in API13")]
122 public ICollection<EmailRecipient> To
131 /// The collection of CC (carbon copy) email recipients.
134 /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
136 /// <since_tizen> 3 </since_tizen>
137 [Obsolete("Deprecated since API11. Might be removed in API13")]
138 public ICollection<EmailRecipient> Cc
147 /// The collection of BCC (blind carbon copy) email recipients.
150 /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
152 /// <since_tizen> 3 </since_tizen>
153 [Obsolete("Deprecated since API11. Might be removed in API13")]
154 public ICollection<EmailRecipient> Bcc
168 ret = Interop.Email.SaveEmail(_emailHandle);
169 if (ret != (int)EmailError.None)
171 Log.Error(EmailErrorFactory.LogTag, "Failed to save email, Error code: " + (EmailError)ret);
172 throw EmailErrorFactory.GetException(ret);
177 /// Releases all resources used by the EmailMessage.
179 /// <since_tizen> 3 </since_tizen>
180 [Obsolete("Deprecated since API11. Might be removed in API13")]
181 public void Dispose()
184 GC.SuppressFinalize(this);
188 /// Releases all resources used by the EmailMessage.
190 /// <param name="disposing">Disposing by User</param>
191 /// <since_tizen> 3 </since_tizen>
192 [Obsolete("Deprecated since API11. Might be removed in API13")]
193 protected virtual void Dispose(bool disposing)
203 if (_emailHandle != IntPtr.Zero)
205 Interop.Email.DestroyEmail(_emailHandle);
206 _emailHandle = IntPtr.Zero;
211 internal void FillHandle()
213 int ret = (int)EmailError.None;
214 foreach (EmailAttachment it in Attachments)
216 Console.WriteLine(it.FilePath);
217 ret = Interop.Email.AddAttachment(_emailHandle, it.FilePath);
218 if (ret != (int)EmailError.None)
220 Log.Error(EmailErrorFactory.LogTag, "Failed to add attachment, Error code: " + (EmailError)ret);
221 throw EmailErrorFactory.GetException(ret);
225 foreach (EmailRecipient it in To)
227 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.To, it.Address);
228 if (ret != (int)EmailError.None)
230 Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
231 throw EmailErrorFactory.GetException(ret);
235 foreach (EmailRecipient it in Cc)
237 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Cc, it.Address);
238 if (ret != (int)EmailError.None)
240 Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
241 throw EmailErrorFactory.GetException(ret);
245 foreach (EmailRecipient it in Bcc)
247 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Bcc, it.Address);
248 if (ret != (int)EmailError.None)
250 Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
251 throw EmailErrorFactory.GetException(ret);