private void HandleMailMessage(object sender, MessageEventArgs e) { try { JsonNIMailConfirmation mail = JsonConvert.DeserializeObject <JsonNIMailConfirmation>(e.Data); if (mail.uniqueId == result.uniqueId) { result = mail; gotResult.Set(); } } catch (Exception) { } }
public JsonNIMailConfirmation SendMail(string from, string subject, string body, params string[] recipients) { JsonNIMail mail = new JsonNIMail(from, subject, body, recipients); mail.uniqueId = JsonConvert.SerializeObject(mail).GetHashCode().ToString(); result = mail.Validate(); result.msg = "Timeout"; Subscribe(mail.uniqueId); OnMessage += HandleMailMessage; Send("SendMail", JsonConvert.SerializeObject(mail)); gotResult = new ManualResetEvent(false); gotResult.WaitOne(10000); Unsubscribe(mail.uniqueId); return(result); }
public JsonNIMailConfirmation Validate() { JsonNIMailConfirmation result = new JsonNIMailConfirmation(uniqueId); if (string.IsNullOrWhiteSpace(from)) { from = "*****@*****.**"; } else { if (!from.EndsWith("@ch.abb.com")) { result.valid = false; result.msg += "Invalid sender: " + from + Environment.NewLine; } } if (string.IsNullOrWhiteSpace(subject)) { subject = "<no subject>"; } if (string.IsNullOrWhiteSpace(body)) { subject = "<no body>"; } if (recipients.Length == 0) { result.valid = false; result.msg += "No recipient" + Environment.NewLine; } foreach (string r in recipients) { if (!r?.EndsWith("@ch.abb.com") ?? true) { result.valid = false; result.msg += "Invalid recipient: " + r + Environment.NewLine; } } return(result); }