Advertisement
Advertisement
| 08.21.2008 at 11:07PM PDT, ID: 23669377 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: |
private Exception SendEMail(string mailSubject, string mailBody, MailAddress mailFrom, MailAddressCollection mailReplyTo, MailAddressCollection mailTo, MailAddressCollection mailCC, MailAddressCollection mailBCC, List<string> mailAttachments)
{
Exception result = null;
MailMessage EMail = new MailMessage();
//Prepare EMail
try
{
EMail.Subject = mailSubject;
EMail.Body = mailBody;
EMail.From = mailFrom;
foreach (MailAddress address in mailTo)
{
EMail.To.Add(address);
}
foreach (MailAddress address in mailCC)
{
EMail.CC.Add(address);
}
foreach (MailAddress address in mailBCC)
{
EMail.Bcc.Add(address);
}
foreach (MailAddress address in mailReplyTo)
{
EMail.ReplyTo = address;
}
//Attachments
foreach (string attFile in mailAttachments)
{
if (File.Exists(attFile))
{
Attachment newAttachment = new Attachment(attFile);
EMail.Attachments.Add(newAttachment);
}
}
//Additional settings
EMail.IsBodyHtml = true;
//Send EMail
//Read smtp host settings
PvConfigurationEntity smtpHost = new PvConfigurationEntity();
smtpHost.FetchUsingUCCfg_Key("SMTPHost");
PvConfigurationEntity smtpUserName = new PvConfigurationEntity();
smtpUserName.FetchUsingUCCfg_Key("SMTPUserName");
PvConfigurationEntity smtpUserPassword = new PvConfigurationEntity();
smtpUserPassword.FetchUsingUCCfg_Key("SMTPUserPassword");
if (smtpHost.Cfg_Value != null && smtpHost.Cfg_Value != "")
{
//Create smtp client
System.Net.Mail.SmtpClient SmtpClient = new System.Net.Mail.SmtpClient();
//Configute smtp client
//Smtp server
SmtpClient.Host = smtpHost.Cfg_Value;
//Smtp authentication
if (smtpUserName.Cfg_Value != null && smtpUserName.Cfg_Value != "")
{
//Use user credentials
SmtpClient.Credentials = new NetworkCredential(smtpUserName.Cfg_Value, smtpUserPassword.Cfg_Value);
}
//Wire up the event for when the Async send is completed
SmtpClient.SendCompleted += new SendCompletedEventHandler(SmtpClient_OnCompleted);
//Result object
object userState = EMail;
//Send email
SmtpClient.SendAsync(EMail, userState);
}
}
catch (Exception e)
{
result = e;
}
return result;
}
private void SmtpClient_OnCompleted(object sender, AsyncCompletedEventArgs e)
{
//
//Analyze the result of the email sending
//
//Get the Original MailMessage object
MailMessage mail = (MailMessage)e.UserState;
//Build protocol string
//TO
string summary = mail.Subject + ", To: " + mail.To.ToString();
//CC
if (mail.CC.ToString() != "")
summary += ", CC: " + mail.CC.ToString();
//BCC
if (mail.Bcc.ToString() != "")
summary += ", Bcc: " + mail.Bcc.ToString();
//Attachments
foreach (Attachment att in mail.Attachments)
{
summary += ", Attached: " + att.Name;
}
//FROM
summary += ", From: " + mail.From + ", Date: " + DateTime.Now.ToString();
//Evaluate result
if (e.Cancelled)
{
LogEvent("E-MAIL CANCELED: " + summary, EventLogEntryType.Warning, 101, 100);
}
if (e.Error != null)
{
LogEvent("E-MAIL FAILED: " + summary + "***********" + e.Error.ToString(), EventLogEntryType.Error, 102, 100);
}
else
{
LogEvent("E-MAIL SENT: " + summary, EventLogEntryType.Information, 103, 100);
}
//Release all resources and handles on resources (e.a. handle on the attachments)
mail.Dispose();
}
|