/// <summary> /// Set Bcc Address to the Mail /// </summary> /// <param name="mailMessage"></param> /// <param name="mailMsg"></param> private void SetBccAddress(System.Web.Mail.MailMessage mailMessage, MailMessage mailMsg) { try { //checking bccAddress string is null or empty if it not null then add to mail if (!String.IsNullOrEmpty(BccAddress)) { //split the bccAddress string and add to an array string[] bccArray = BccAddress.Split(";".ToCharArray()); ValidateRecipientEmail(bccArray);//validating the email address //if mail is net.mail if (IsSmtpClientMail) { foreach (string bcc in bccArray.Where(bcc => !bcc.Equals(""))) { mailMsg.Bcc.Add(bcc); //add bccAddress array to mailmessage.Bcc } } else { //if mail is web.mail set bccAddress string to MailMessage.Bcc BccAddress = BccAddress.TrimEnd(';'); mailMessage.Bcc = BccAddress; } } else { //bccAddress is null then set BccFlag to 1 BccFlag = 1; } } catch (Exception ex) { throw ex; } }
public bool Send() { bool mailSent = false; try { MailMessage Mail = new MailMessage(); if (ToAddress != null) { ToAddress.ForEach(x => Mail.To.Add(x)); } if (CcAddress != null) { CcAddress.ForEach(x => Mail.CC.Add(x)); } if (BccAddress != null) { BccAddress.ForEach(x => Mail.Bcc.Add(x)); } Mail.From = new MailAddress(this.FromAddress); Mail.Subject = this.Subject; Mail.Body = this.Body; Mail.IsBodyHtml = this.IsBodyHtml; if (Attachments.Count > 0) { foreach (var attchment in Attachments) { Mail.Attachments.Add(attchment); } } SmtpClient SMTP = new SmtpClient(this.SmtpAddress); SMTP.UseDefaultCredentials = false; SMTP.Credentials = new System.Net.NetworkCredential(this.UserName, this.Password); SMTP.Port = this.Port; SMTP.Host = this.SmtpAddress; SMTP.EnableSsl = this.SslEnabled; SMTP.Send(Mail); SMTP.Dispose(); Mail.Dispose(); mailSent = true; } catch (Exception ex) { mailSent = false; } return(mailSent); }
void ControlTreeDataLoader.LoadData() { Attributes.Add( "href", "mailto:" + StringTools.ConcatenateWithDelimiter( "?", ToAddress, StringTools.ConcatenateWithDelimiter( "&", CcAddress.PrependDelimiter("cc="), BccAddress.PrependDelimiter("bcc="), HttpUtility.UrlEncode(Subject).PrependDelimiter("subject="), HttpUtility.UrlEncode(Body).PrependDelimiter("body=")))); CssClass = CssClass.ConcatenateWithSpace("ewfClickable"); ActionControlStyle.SetUpControl(this, ""); if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), this); } }
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); }