void SendMessageToDotNet(SEND_MESSAGE message) { try { DateTime timeNow = DateTime.Now; // from, to MailMessage theMailMessage = new MailMessage(message.from, message.to); if (message.attachment != null) { Attachment newAttachement = new Attachment(message.attachment); theMailMessage.Attachments.Add(newAttachement); } theMailMessage.Body = message.body; theMailMessage.Subject = message.subject; SmtpClient theClient = new SmtpClient(EmaiSettings.OutBoundServer); theClient.UseDefaultCredentials = false; System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential(EmaiSettings.UserName, EmaiSettings.Password); theClient.Credentials = theCredential; theClient.SendCompleted += new SendCompletedEventHandler(theClient_SendCompleted); // The userState can be any object that allows your callback // method to identify this send operation. string userState = message.Mail_Key; theClient.SendAsync(theMailMessage, userState); } catch (Exception ex) { SEND_RESULT result = new SEND_RESULT(); result.Commentary = ex.Message; result.Success = false; result.Mail_Key = message.Mail_Key; m_SendResultQ.Enqueue(result); m_Log.Log("SendMessageToDotNet ex: " + result.Commentary, ErrorLog.LOG_TYPE.INFORMATIONAL); } }
void theClient_SendCompleted(object sender, AsyncCompletedEventArgs e) { try { string mailKey = (string)e.UserState; object callBack = m_SendResultEvents[mailKey]; if (callBack != null) { SEND_RESULT result = new SEND_RESULT(); result.Mail_Key = mailKey; if (e.Error != null || e.Cancelled) { result.Success = false; if (e.Cancelled) { result.Commentary = "Send Cancelled"; } else { result.Commentary = e.Error.Message; } } else { result.Commentary = "Send Message Sucessful"; result.Success = true; } m_SendResultQ.Enqueue(result); } } catch (Exception ex) { m_Log.Log("theClient_SendCompleted ex: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL); } }
void theClient_SendCompleted(object sender, AsyncCompletedEventArgs e) { try { string mailKey =(string) e.UserState; object callBack = m_SendResultEvents[mailKey]; if (callBack != null) { SEND_RESULT result = new SEND_RESULT(); result.Mail_Key = mailKey; if (e.Error != null || e.Cancelled) { result.Success = false; if (e.Cancelled) result.Commentary = "Send Cancelled"; else result.Commentary = e.Error.Message; } else { result.Commentary = "Send Message Sucessful"; result.Success = true; } m_SendResultQ.Enqueue(result); } } catch (Exception ex) { m_Log.Log("theClient_SendCompleted ex: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL); } }
void SendMessageToDotNet(SEND_MESSAGE message) { try { DateTime timeNow = DateTime.Now; // from, to MailMessage theMailMessage = new MailMessage(message.from,message.to); if (message.attachment != null) { Attachment newAttachement = new Attachment(message.attachment); theMailMessage.Attachments.Add(newAttachement); } theMailMessage.Body = message.body; theMailMessage.Subject = message.subject; SmtpClient theClient = new SmtpClient(EmaiSettings.OutBoundServer); theClient.UseDefaultCredentials = false; System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential(EmaiSettings.UserName, EmaiSettings.Password); theClient.Credentials = theCredential; theClient.SendCompleted += new SendCompletedEventHandler(theClient_SendCompleted); // The userState can be any object that allows your callback // method to identify this send operation. string userState = message.Mail_Key; theClient.SendAsync(theMailMessage, userState); } catch (Exception ex) { SEND_RESULT result = new SEND_RESULT(); result.Commentary = ex.Message ; result.Success = false; result.Mail_Key = message.Mail_Key; m_SendResultQ.Enqueue(result); m_Log.Log("SendMessageToDotNet ex: " + result.Commentary, ErrorLog.LOG_TYPE.INFORMATIONAL); } }