public void TestEmailAddress() { EmailAddress email = new EmailAddress("*****@*****.**", "Dr. Who"); bool valid = email.Valid; //True string emailValue = email.Value; //[email protected] string domain = email.Domain; //where.com string username = email.User; //who string name = email.Name; //Dr. Who string formatted = email.EmailWithName; //Dr. Who <*****@*****.**> string emailToString = email.ToString(); //[email protected] string emailStringImplicit = (string)email; //[email protected] string link = email.ToLink(); //<a href="mailto:[email protected]">[email protected]</a> object sqlObj = email.ToSql(); //[email protected] or DBNull.Value when empty Assert.IsTrue(valid); Assert.AreEqual(emailValue, "*****@*****.**"); Assert.AreEqual(domain, "where.com"); Assert.AreEqual(username, "who"); Assert.AreEqual(name, "Dr. Who"); Assert.AreEqual(formatted, "Dr. Who <*****@*****.**>"); Assert.AreEqual(emailToString, "*****@*****.**"); Assert.AreEqual(emailStringImplicit, "*****@*****.**"); Assert.AreEqual(link, "<a href=\"mailto:[email protected]\">[email protected]</a>"); Assert.AreEqual(sqlObj, "*****@*****.**"); }
/// <summary> /// Creates a new AddressBookEntry /// </summary> public AddressBookEntry(string FirstName, string LastName, PhoneNumber Phone, EmailAddress Email, string Reference,string Address1,string Address2,string Address3,string City,string StateCode,string PostalCode,string CountryCode) : base(Reference, Address1, Address2, Address3, City, StateCode, PostalCode, CountryCode) { _strFirstName = FirstName; _strLastName = LastName; _objPhone = Phone; _objEmail = Email; }
/// <summary> /// Returns true if an array contains a specified value /// </summary> public static bool Contains(EmailAddress[] Array,EmailAddress Value) { foreach(object i in Array) { if(i.ToString() == Value.ToString()) return true; } return false; }
public AveryBarcodeLabel(string strLine1, string strLine2, string strLine3, PhoneNumber objPhone, EmailAddress objEmail, DateTime objDate) { InitializeComponent(); //set visual elements Line1 = strLine1; Line2 = strLine2; Line3 = strLine3; Phone = objPhone; Email = objEmail; Date = objDate; }
/// <summary> /// Compares two objects and breaks the data integrity seal if the objects are not equal. /// </summary> protected EmailAddress PokeSeal(EmailAddress OldValue, EmailAddress NewValue) { if(OldValue != NewValue) BreakSeal(); return(NewValue); }
/// <summary> /// Email the log /// </summary> public void Send(EmailAddress Recipient, string Subject) { General.Mail.MailTools.SendEmail(GlobalConfiguration.GlobalSettings["debug_email_from"],Recipient.ToString(),Subject,_log,false); }
public static bool SendEmail(EmailAddress FromEmail, System.Collections.ArrayList ToEmail, string Subject, string Body, bool IsHtml, System.Collections.ArrayList Attachments) { MailMessage objMailMessage = new MailMessage(); objMailMessage.From = new MailAddress(FromEmail,FromEmail.Name); if (Environment.Current.AmIDev()) { objMailMessage.To.Add(new MailAddress(General.Debugging.Report.DebugEmailTo)); if (ToEmail.Count > 1) { string strRecipients = ""; foreach (EmailAddress objEmail in ToEmail) { if (!StringFunctions.IsNullOrWhiteSpace(objEmail.ToString())) strRecipients += objEmail.EmailWithName + ","; } strRecipients = StringFunctions.Shave(strRecipients, 1); Body = "Recipients(" + ToEmail.Count + "): " + strRecipients + "\n" + Body; } } else { foreach (EmailAddress objEmail in ToEmail) { if(objEmail != null) if (objEmail.Valid) { if (SendWithBCC) { if (StringFunctions.IsNullOrWhiteSpace(objEmail.Name)) objMailMessage.Bcc.Add(objEmail.Value); else objMailMessage.Bcc.Add(new MailAddress(objEmail, objEmail.Name)); } else { if (StringFunctions.IsNullOrWhiteSpace(objEmail.Name)) objMailMessage.To.Add(objEmail.Value); else objMailMessage.To.Add(new MailAddress(objEmail, objEmail.Name)); } } } } objMailMessage.Subject = Subject; objMailMessage.Body = Body; objMailMessage.IsBodyHtml = IsHtml; if(Attachments != null) { foreach(string s in Attachments) { if(File.Exists(s)) { Attachment objAttachment = new Attachment(s); objMailMessage.Attachments.Add(objAttachment); } } } System.Net.Mail.SmtpClient objMailServer; if (SendWithBulkMailServer && ToEmail.Count > 1 && !StringFunctions.IsNullOrWhiteSpace(MailServerBulkEmail)) objMailServer = GetMailServer(MailServerTypes.Bulk); else if (!Environment.Current.AmIDev() && !StringFunctions.IsNullOrWhiteSpace(MailServerDebug) && ToEmail.Count == 1 && (((EmailAddress)ToEmail[0]) == new EmailAddress(Debugging.Report.ErrorEmailTo) || ((EmailAddress)ToEmail[0]) == new EmailAddress(Debugging.Report.DebugEmailTo))) objMailServer = GetMailServer(MailServerTypes.Debug); else objMailServer = GetMailServer(MailServerTypes.Normal); try { objMailServer.Send(objMailMessage); } catch(Exception ex) { foreach (EmailAddress objEmail in ToEmail) //IF YOU REMOVE THIS CONDITION THE SERVER WILL CRASH (INFINITE RECURSION) if (objEmail == new EmailAddress(Debugging.Report.ErrorEmailTo)) throw new Exception("Error sending debug email", ex); try { SendEmail(Debugging.Report.ErrorEmailFrom, Debugging.Report.ErrorEmailTo, "Email Send Error", ex.ToString()); } catch { } throw; } return true; }
/// <summary> /// Send an email /// </summary> public static bool SendEmail(EmailAddress FromEmail, EmailAddress ToEmail, string Subject, string Body, bool IsHtml) { return (SendEmail(FromEmail.ToString(), ToEmail.ToString(), Subject, Body, IsHtml)); }
public static bool SendEmail(EmailAddress FromEmail, EmailAddress ToEmail, string Subject, string Body, bool IsHtml, System.Collections.ArrayList Attachments) { System.Collections.ArrayList aryToEmail = new System.Collections.ArrayList(); aryToEmail.Add(ToEmail); return SendEmail(FromEmail, aryToEmail, Subject, Body, IsHtml, Attachments); }
public static bool SendEmail(EmailAddress FromEmail, EmailAddress ToEmail, string Subject, string Body, bool IsHtml, string[] Attachments) { System.Collections.ArrayList aryAttachments = null; if(Attachments != null) { aryAttachments = new System.Collections.ArrayList(); foreach (string s in Attachments) aryAttachments.Add(s); } return SendEmail(FromEmail, ToEmail, Subject, Body, IsHtml, aryAttachments); }
/// <summary> /// Convert a string into a EmailAddress object /// </summary> public static object ToSql(EmailAddress input) { if (input == null) return DBNull.Value; else return input.ToSql(); }