public virtual string[] GetCC() { if (string.IsNullOrEmpty(CCAddress)) { return new string[] { } } ; else { return(CCAddress.Split(',')); } }
/// <summary> /// Sending mail in GF Networks /// </summary> /// <param name="recipeient">Receiver(Optional wil set to default recipients)</param> /// <param name="subject">Subject for the mail</param> /// <param name="bodyText">Content for the mail body</param> public static bool SendMail(string subject, string body) { try { if (EnableMails != "true") { return(false); } MailMessage mMailMessage = new MailMessage(); mMailMessage.From = new MailAddress(FromAddress); foreach (var item in ToAddress.Split(';')) { mMailMessage.To.Add(item); } foreach (var item in CCAddress.Split(';')) { mMailMessage.CC.Add(item); } mMailMessage.Subject = subject; mMailMessage.Body = body; mMailMessage.Priority = MailPriority.High; SmtpClient mSmtpClient = new SmtpClient(); mSmtpClient.Host = SmtpServer; if (Port != string.Empty) { mSmtpClient.Port = Convert.ToInt32(Port);// 587 } mSmtpClient.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; mSmtpClient.Send(mMailMessage); } catch (SmtpException ex) { string strError = ex.Message; return(false); } catch (Exception ex) { string strError = ex.Message; return(false); } return(true); }
public void Send() { var message = new MailMessage(); var toAddresses = ToAddress.Split(';'); var ccAddresses = CCAddress.Split(';'); var bccaddresses = BccAddress.Split(';'); try { foreach (String address in toAddresses) { message.To.Add(address); } } catch (Exception ex) { Console.WriteLine("The To Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { foreach (String address in ccAddresses) { message.CC.Add(address); } } catch (Exception ex) { Console.WriteLine("The CC Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { foreach (String address in bccaddresses) { message.Bcc.Add(address); } } catch (Exception ex) { Console.WriteLine("The BCC Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } try { message.From = new MailAddress(FromAddress); } catch (Exception ex) { Console.WriteLine("The From Address field contained bad input."); Console.WriteLine("A valid email address may only contain letters, numbers, an underscore, a dash, a period, or an @ symbol."); } message.Subject = Subject; message.Body = MessageBody; message.IsBodyHtml = IsBodyHtml; client.Send(message); }