public override void EstablishContext() { _emailMessage = new EmailMessage( ); _emailMessage.AddAttachment( @"c:\file1.txt" ); _emailMessage.AddAttachment( @"c:\file2.txt" ); _emailMessage.AddRecipient( @"*****@*****.**" ); _emailMessage.AddRecipient( @"*****@*****.**" ); }
public override void EstablishContext() { _emailMessage = new EmailMessage( ); _emailMessage.AddAttachment(@"c:\file1.txt"); _emailMessage.AddAttachment(@"c:\file2.txt"); _emailMessage.AddRecipient(@"*****@*****.**"); _emailMessage.AddRecipient(@"*****@*****.**"); }
/// <summary> /// Add an attachment to the mail /// </summary> public Boolean AddAttachment(String FilePathAndName) { return(_mail.AddAttachment(FilePathAndName)); }
bool AssignEmailHeaderToMailMessage(string key, string value, EmailMessage message) { if (string.IsNullOrWhiteSpace(value)) { return(false); } string email = value.Trim().Trim(';'); string displayName = null; var match = System.Text.RegularExpressions.Regex.Match(email, "<(?<email>.*[^>)])>"); if (match.Success) { email = match.Groups["email"].Value; displayName = value.Replace("<" + email + ">", "").Trim(); } bool headerAdded = true; switch (key) { case "to": var toEmailList = email.Split(';'); foreach (var e in toEmailList) { var to = new EmailAddress() { Address = e, DisplayName = displayName, SendingType = EmailSendingType.To }; if (!message.Recipients.Any(i => i.Address.Equals(to.Address, StringComparison.InvariantCultureIgnoreCase))) { message.Recipients.Add(to); } } break; case "from": //message.Sender = new Sender() //{ // Email = email, // DisplayName = displayName //}; break; case "subject": message.Subject = value; break; case "cc": var ccEmailList = email.Split(';'); foreach (var e in ccEmailList) { var cc = new EmailAddress() { Address = e, DisplayName = displayName, SendingType = EmailSendingType.CC }; message.Recipients.Add(cc); } break; case "bcc": var emailList = email.Split(';'); foreach (var e in emailList) { var bcc = new EmailAddress() { Address = e, SendingType = EmailSendingType.BCC }; message.Recipients.Add(bcc); } break; case "replyto": var replyto = new EmailAddress() { Address = email, DisplayName = displayName, SendingType = EmailSendingType.ReplyTo }; message.Recipients.Add(replyto); break; case "return-path": var returnPath = new EmailAddress() { Address = email, DisplayName = displayName, SendingType = EmailSendingType.ReturnPath }; message.Recipients.Add(returnPath); break; case "attachment": var attachement = value.Split('|'); var fileName = attachement[2].Replace('/', '\\').TrimStart('\\'); fileName = System.IO.Path.Combine(GlobalConfiguration.Configuration.PhysicalPath.TrimEnd('\\'), fileName); message.AddAttachment(attachement[0], attachement[1], fileName); break; default: // message.Headers[key] = value; headerAdded = false; break; } return(headerAdded); }
private bool Send(string from, string to, string cc, string bcc, string subject, string body, Stream stream, string filename , string SmtpServer, string SmtpUserName, string SmtpPassword, int SmtpPort, bool SmtpUseSsl) { EmailMessage _EmailMessage = new EmailMessage(); _EmailMessage.Server = SmtpServer; if (!String.IsNullOrEmpty(SmtpUserName)) _EmailMessage.Username = SmtpUserName; if (!String.IsNullOrEmpty(SmtpPassword)) _EmailMessage.Password = SmtpPassword; if (SmtpPort != 0) _EmailMessage.Port = SmtpPort; if (SmtpUseSsl) _EmailMessage.LoadSslSocket(new AdvancedIntellect.Ssl.SslSocket()); // create the ssl socket //Trace.Warn("_EmailMessage.Server", _EmailMessage.Server); //Trace.Warn("_EmailMessage.Username", _EmailMessage.Username); //Trace.Warn("_EmailMessage.Password", _EmailMessage.Password); //Trace.Warn("_EmailMessage.Port", _EmailMessage.Port.ToString()); _EmailMessage.FromAddress = from; _EmailMessage.To = to; if (!String.IsNullOrEmpty(cc)) _EmailMessage.Cc = cc; if (!String.IsNullOrEmpty(bcc)) _EmailMessage.Bcc = bcc; _EmailMessage.Subject = subject; _EmailMessage.Body = body; _EmailMessage.CharSet = "utf-8"; _EmailMessage.BodyFormat = MailFormat.Html; Attachment _attach = new Attachment(stream, filename); _EmailMessage.AddAttachment(_attach); return _EmailMessage.Send(); }