static void Main(string[] args) { // Create attendees of the meeting MailAddressCollection attendees = new MailAddressCollection(); attendees.Add("*****@*****.**"); attendees.Add("*****@*****.**"); // Set up appointment Appointment app = new Appointment( "Location", // location of meeting DateTime.Now, // start date DateTime.Now.AddHours(1), // end date new MailAddress("*****@*****.**"), // organizer attendees); // attendees // Set up message that needs to be sent MailMessage msg = new MailMessage(); msg.From = "*****@*****.**"; msg.To = "*****@*****.**"; msg.Subject = "appointment request"; msg.Body = "you are invited"; // Add meeting request to the message msg.AddAlternateView(app.RequestApointment()); // Set up the SMTP client to send email with meeting request SmtpClient client = new SmtpClient("host", 25, "user", "password"); client.Send(msg); }
private void CreateMailMessage(DeliveryInfo deliveryInfo, MailMessage message) { var recipients = deliveryInfo.To; if (string.IsNullOrEmpty(recipients)) throw new ArgumentNullException(recipients); var addressCollection = new MailAddressCollection(); if (!MailSettings.UseEmailTestMode) addressCollection.Add(recipients); else addressCollection.Add(MailSettings.TestEmailAddress); foreach (var address in addressCollection) { message.To.Add(EmailHelper.FixMailAddressDisplayName(address, MailSettings.EmailHeaderEncoding)); } message.From = EmailHelper.FixMailAddressDisplayName(new MailAddress(deliveryInfo.From), MailSettings.EmailHeaderEncoding); message.BodyEncoding = Encoding.GetEncoding(MailSettings.EmailBodyEncoding); message.SubjectEncoding = Encoding.GetEncoding(MailSettings.EmailSubjectEncoding); message.HeadersEncoding = Encoding.GetEncoding(MailSettings.EmailHeaderEncoding); message.Body = deliveryInfo.Body; message.IsBodyHtml = deliveryInfo.IsBodyHtml; message.Subject = deliveryInfo.Subject; if (!string.IsNullOrEmpty(deliveryInfo.ReplyTo)) { var replyToCollection = new MailAddressCollection { deliveryInfo.ReplyTo }; foreach (var address in replyToCollection) { message.ReplyToList.Add(EmailHelper.FixMailAddressDisplayName(address, MailSettings.EmailHeaderEncoding)); } } }
public static void Run() { // ExStart:GetMailTips // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); Console.WriteLine("Connected to Exchange server..."); // Provide mail tips options MailAddressCollection addrColl = new MailAddressCollection(); addrColl.Add(new MailAddress("*****@*****.**", true)); addrColl.Add(new MailAddress("*****@*****.**", true)); GetMailTipsOptions options = new GetMailTipsOptions("*****@*****.**", addrColl, MailTipsType.All); // Get Mail Tips MailTips[] tips = client.GetMailTips(options); // Display information about each Mail Tip foreach (MailTips tip in tips) { // Display Out of office message, if present if (tip.OutOfOffice != null) { Console.WriteLine("Out of office: " + tip.OutOfOffice.ReplyBody.Message); } // Display the invalid email address in recipient, if present if (tip.InvalidRecipient == true) { Console.WriteLine("The recipient address is invalid: " + tip.RecipientAddress); } } // ExEnd:GetMailTips }
public static void Run() { // ExStart:AddMembersToPrivateDistributionList IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); MailAddressCollection newMembers = new MailAddressCollection(); newMembers.Add("*****@*****.**"); newMembers.Add("*****@*****.**"); client.AddToDistributionList(distributionLists[0], newMembers); // ExEnd:AddMembersToPrivateDistributionList }
public static void Run() { // ExStart:DeleteMembersFromPrivateDistributionList IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); MailAddressCollection members = client.FetchDistributionList(distributionLists[0]); MailAddressCollection membersToDelete = new MailAddressCollection(); membersToDelete.Add(members[0]); membersToDelete.Add(members[1]); client.DeleteFromDistributionList(distributionLists[0], membersToDelete); // ExEnd:DeleteMembersFromPrivateDistributionList }
public static void Run() { // ExStart:CreatePrivateDistributionList IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); ExchangeDistributionList distributionList = new ExchangeDistributionList(); distributionList.DisplayName = "test private list"; MailAddressCollection members = new MailAddressCollection(); members.Add("*****@*****.**"); members.Add("*****@*****.**"); members.Add("*****@*****.**"); client.CreateDistributionList(distributionList, members); // ExEnd:CreatePrivateDistributionList }
public static void Enviar(MailAddress to, String body, String subject, List<Attachment> attachments) { MailAddressCollection emails = new MailAddressCollection(); emails.Add(to); MailAddress from = Util.Email.EmailEnvioPadrao; Enviar(from, emails, body, subject, attachments); }
static void AddMailAddress(MailAddressCollection collection, String address) { if (String.IsNullOrEmpty(address)) return; if (address.Contains(";")) { String[] recipients = address.Split(';'); foreach (String recipient in recipients) collection.Add(recipient); } else { collection.Add(address); } }
public void SendAnEmail() { try { MailMessage _message = new MailMessage(); SmtpClient _smptClient = new SmtpClient(); _message.Subject = _emailSubject; _message.Body = _emailBody; MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName); MailAddressCollection _mailTo = new MailAddressCollection(); _mailTo.Add(_emailTo); _message.From = _mailFrom; _message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName)); System.Net.NetworkCredential _crens = new System.Net.NetworkCredential( _smtpHostUserName,_smtpHostPassword); _smptClient.Host = _smtpHost; _smptClient.Credentials = _crens; _smptClient.Send(_message); } catch (Exception er) { Log("C:\\temp\\", "Error.log", er.ToString()); } }
public void SendAnEmail() { bool _success = false; try { MailMessage _message = new MailMessage(); SmtpClient _smptClient = new SmtpClient(); _message.Subject = _emailSubject; _message.Body = _emailBody; MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName); MailAddressCollection _mailTo = new MailAddressCollection(); _mailTo.Add(_emailTo); _message.From = _mailFrom; _message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName)); System.Net.NetworkCredential _crens = new System.Net.NetworkCredential( _smtpHostUserName,_smtpHostPassword); _smptClient.Host = _smtpHost; _smptClient.Credentials = _crens; _smptClient.Send(_message); } catch (Exception er) { string s1 = er.Message; } }
public static void Send(MailAddress from, MailAddress replyTo, MailAddress to, string subject, string body) { MailAddressCollection toList = new MailAddressCollection(); toList.Add(to); Send(from, replyTo, toList, subject, body); }
private void Populate(MailAddressCollection dest, IEnumerable<string> source) { foreach (string mail in source) { dest.Add(FromString(mail)); } }
internal override MailAddress[] ParseAddressList(string list) { List<MailAddress> mails = new List<MailAddress>(); if (string.IsNullOrEmpty(list)) return mails.ToArray(); foreach (string part in SplitAddressList(list)) { MailAddressCollection mcol = new MailAddressCollection(); try { // .NET won't accept address-lists ending with a ';' or a ',' character, see #68. mcol.Add(part.TrimEnd(';', ',')); foreach (MailAddress m in mcol) { // We might still need to decode the display name if it is Q-encoded. string displayName = Util.DecodeWords(m.DisplayName); mails.Add(new MailAddress(m.Address, displayName)); } } catch { // We don't want this to throw any exceptions even if the entry is malformed. } } return mails.ToArray(); }
public void CopyToMailAddressCollection(Rebex.Mime.Headers.MailAddressCollection rmac, MailAddressCollection mac) { foreach (Rebex.Mime.Headers.MailAddress rma in rmac) { mac.Add(ToMailAddress(rma)); } }
/// <summary> /// Adds the mails to the address-collection. /// </summary> /// <param name="collection">The collection.</param> /// <param name="addresses">The addresses.</param> private void AddMailsToCollection(MailAddressCollection collection, IEnumerable<string> addresses) { foreach (string address in addresses) { collection.Add(new MailAddress(address)); } }
/// <summary> /// Send a plain text email with the specified properties. The email will appear to come from the name and email specified in the /// EmailFromName and EmailFromAddress configuration settings. If the emailRecipient parameter is not specified, the email /// is sent to the address configured in the emailToAddress setting in the configuration file. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If it is important to know if the e-mail was successfully sent, use the overload of this /// method that specifies a sendOnBackgroundThread parameter. /// </summary> /// <param name="emailRecipient">The recipient of the email.</param> /// <param name="subject">The text to appear in the subject of the email.</param> /// <param name="body">The body of the email. If the body is HTML, specify true for the isBodyHtml parameter.</param> public static void SendEmail(MailAddress emailRecipient, string subject, string body) { MailAddressCollection mailAddresses = new MailAddressCollection(); mailAddresses.Add(emailRecipient); SendEmail(mailAddresses, subject, body, false, true); }
private static void PopulateAddresses(string recipients, MailAddressCollection collection) { if (string.IsNullOrEmpty(recipients)) return; if (collection == null) return; var split = recipients.Split(';'); foreach (var s in split) collection.Add(s); }
/// <summary> /// Populates <paramref name="target"/> with properties copied from <paramref name="source"/>. /// </summary> /// <param name="source">The source object to copy.</param> /// <param name="target">The target object to populate.</param> private void Convert(MailAddressSerializableList source, MailAddressCollection target) { if (source == null) { return; } source.ForEach(s => target.Add(this.Convert(s))); }
private static string GetAddress(ICollection<string> addresses) { var ColletionAddressess = new MailAddressCollection(); foreach (var address in addresses) { ColletionAddressess.Add(new MailAddress(address)); } return String.Join(",", ColletionAddressess.Select(address => address.Address).ToArray()); }
public static void Send(string from, string fromName, string replyTo, string replyToName, string[] to, string subject, string body) { MailAddressCollection toList = new MailAddressCollection(); foreach (string item in to) { toList.Add(new MailAddress(item)); } Send(new MailAddress(from, fromName), new MailAddress(replyTo, replyToName), toList, subject, body); }
private void AddMailAddress(MailAddressCollection collection, IEnumerable<string> addressList) { if (collection == null || addressList == null) return; foreach (string add in addressList) { collection.Add(add); } }
public void Add_WithAddressAndDisplayName_DoesAdd() { // Arrange var collection = new MailAddressCollection(); // Act collection.Add(ObjectMother.To.Address, ObjectMother.To.DisplayName); // Assert Assert.That(collection, Has.Member(ObjectMother.To)); }
static void Main(string[] args) { string location = "Meeting Location: Room 5"; DateTime startDate = new DateTime(1997, 3, 18, 18, 30, 00), endDate = new DateTime(1997, 3, 18, 19, 30, 00); MailAddress organizer = new MailAddress("*****@*****.**", "Organizer"); MailAddressCollection attendees = new MailAddressCollection(); attendees.Add(new MailAddress("*****@*****.**", "First attendee")); Appointment target = new Appointment(location, startDate, endDate, organizer, attendees); target.Save("savedFile.ics"); }
public static void Run() { // ExStart:AddMembersWithoutListing IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); ExchangeDistributionList distributionList = new ExchangeDistributionList(); distributionList.Id = "list's id"; distributionList.ChangeKey = "list's change key"; MailAddressCollection newMembers = new MailAddressCollection(); newMembers.Add("*****@*****.**"); client.AddToDistributionList(distributionList, newMembers); // ExEnd:AddMembersWithoutListing }
static MailAddressCollection UnsafeParseMailAddressCollection(string addressesString) { var result = new MailAddressCollection(); if (addressesString.Trim() == "") return result; var addressStrings = addressesString.Split(';'); foreach (var s in addressStrings) result.Add(s); return result; }
private static void FillAddress(MailAddressCollection addressCollection, string addressContent) { if (!string.IsNullOrEmpty(addressContent)) { foreach (string str in addressContent.Split(MailInfo.MailAddrSpliters)) { if (!string.IsNullOrEmpty(str)) { addressCollection.Add(str); } } } }
private static void AddEmailAddresses( MailAddressCollection mailAddressCollection, IReadOnlyCollection <EmailMailbox> emailMailboxes) { if (emailMailboxes != null) { foreach (var emailMailbox in emailMailboxes) { var mailAddress = emailMailbox.ToMailAddress(); mailAddressCollection.Add(mailAddress); } } }
public bool SendContactMessageAlert(string senderName, DateTime date, string messageUrl) { MailAddress from = new MailAddress(Settings.Default.CustomerServiceEmail, "Customer Service (for " + senderName + ")"); MailAddressCollection tos = new MailAddressCollection(); tos.Add(new MailAddress(Settings.Default.CompanyContactEmail)); string subject = "New contact message"; StringBuilder sbMessage = new StringBuilder(); string message = "<div>Read message at " + messageUrl + ".</div>"; string body = StandardHtmlFormattedMessage("New contact message", message, false); return(SendMessage(from, null, tos, null, null, subject, body, true)); }
public void EncodeMultipleMailAddress_WithManyAddressesThatAreDifferentAndContainUnicode_ShouldEncodeCorrectly() { MailAddress testAddress = new MailAddress("*****@*****.**", "test"); MailAddress testAddress2 = new MailAddress("*****@*****.**", "testÜ"); MailAddress testAddress3 = new MailAddress("*****@*****.**"); MailAddress testAddress4 = new MailAddress("*****@*****.**", "testÜ"); MailAddressCollection collection = new MailAddressCollection(); collection.Add(testAddress); collection.Add(testAddress2); collection.Add(testAddress3); collection.Add(testAddress4); string result = collection.Encode(0, false); Assert.Equal("\"test\" <*****@*****.**>, =?utf-8?Q?test=C3=9C?= <*****@*****.**>," + " [email protected], =?utf-8?Q?test=C3=9C?= <*****@*****.**>", result); result = collection.Encode(0, true); Assert.Equal("\"test\" <*****@*****.**>, \"testÜ\" <*****@*****.**>, [email protected]," + " \"testÜ\" <*****@*****.**>", result); }
public void EncodeMultipleMailAddress_WithOneAddressAndDisplayName_ShouldEncodeAsDisplayNameAndAddressInBrackets() { MailAddress testAddress = new MailAddress("*****@*****.**", "test"); MailAddressCollection collection = new MailAddressCollection(); collection.Add(testAddress); string result = collection.Encode(0, false); Assert.Equal("\"test\" <*****@*****.**>", result); result = collection.Encode(0, true); Assert.Equal("\"test\" <*****@*****.**>", result); }
private static MailAddressCollection emaillist(string emailaddress) { MailAddressCollection addressList = new MailAddressCollection(); foreach (var curr_address in emailaddress.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { if (curr_address.Trim() != "") { MailAddress myAddress = new MailAddress(curr_address.Trim()); addressList.Add(myAddress); } } return(addressList); }
public static void Run() { // ExStart:DeleteMembersWithoutListing IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); ExchangeDistributionList distributionList = new ExchangeDistributionList(); distributionList.Id = "list's id"; distributionList.ChangeKey = "list's change key"; MailAddressCollection membersToDelete = new MailAddressCollection(); MailAddress addressToDelete = new MailAddress("address", true); //addressToDelete.Id.EWSId = "member's id"; membersToDelete.Add(addressToDelete); client.AddToDistributionList(distributionList, membersToDelete); // ExEnd:DeleteMembersWithoutListing }
/// <summary> /// 将String(使用英文,隔开)类型转换为MailAddressCollection /// </summary> private void String2MailAddressCollection(MailAddressCollection collection, string emails) { string[] emailStrings = emails.Split(','); if (emailStrings != null && emailStrings.Length > 0) { foreach (string email in emailStrings) { if (!string.IsNullOrEmpty(email.Trim())) { collection.Add(new MailAddress(email)); } } } }
/// <summary> /// Assigns mail addresses from a string or comma delimited string list. /// Facilitates /// </summary> /// <param name="recipients"></param> /// <returns></returns> private void AssignMailAddresses(MailAddressCollection address, string recipients) { if (string.IsNullOrEmpty(recipients)) { return; } string[] recips = recipients.Split(',', ';'); for (int x = 0; x < recips.Length; x++) { address.Add(new MailAddress(recips[x])); } }
private static MailAddressCollection SetRecipients(this MailAddressCollection mac, IEnumerable <string> addresses) { if (mac != null && addresses != null && addresses.Any()) { foreach (var a in addresses) { if (a.Clear() != null) { mac.Add(a); } } } return(mac); }
public async Task Execute(string email, string subject, string message) { try { string ToEmail = _emailSettings.ToEmail; MailAddressCollection TO_addressList = new MailAddressCollection(); //3.Prepare the Destination email Addresses list foreach (var curr_address in ToEmail.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { MailAddress mytoAddress = new MailAddress(curr_address); TO_addressList.Add(mytoAddress); } string CcEmail = _emailSettings.CcEmail; MailAddressCollection Cc_addressList = new MailAddressCollection(); //3.Prepare the Destination email Addresses list foreach (var curr_address in CcEmail.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { MailAddress myCcAddress = new MailAddress(curr_address); Cc_addressList.Add(myCcAddress); } using (MailMessage mail = new MailMessage() { From = new MailAddress(_emailSettings.FromEmail), Subject = "ATapplianceServiceInc.com - " + subject, Body = message, IsBodyHtml = true, Priority = MailPriority.High, }) { mail.To.Add(TO_addressList.ToString()); mail.CC.Add(Cc_addressList.ToString()); using (SmtpClient smtp = new SmtpClient(_emailSettings.SecondayDomain, _emailSettings.SecondaryPort)) { smtp.Host = _emailSettings.PrimaryDomain; smtp.Port = _emailSettings.PrimaryPort; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(_emailSettings.UsernameEmail, _emailSettings.UsernamePassword); smtp.EnableSsl = true; await smtp.SendMailAsync(mail); } } } catch (Exception ex) { //do something here } }
/// <summary> /// Add email address to a MailAddressCollection /// </summary> static public void AddEmailAddresses(MailAddressCollection collection, string input) { if (!string.IsNullOrEmpty(input)) { string[] addresses = input.Replace(";", "\r\n").Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); foreach (string address in addresses) { if (!string.IsNullOrWhiteSpace(address)) { collection.Add(address); } } } }
private void AddMailAddress(MailAddressCollection mailAddressCollection, string mailAddresses) { string[] ss = mailAddresses.Split(';'); foreach (string s in ss) { if (string.IsNullOrEmpty(s)) { continue; } mailAddressCollection.Add(new MailAddress(s)); } }
public static void SendEmail(string Emails, string PathWhereToCopyTo) { try { const string TextBody = "Please see attached .\r\n\n"; SmtpClient Myserver = new SmtpClient { Host = "google.com", Port = 25 }; MailAddress fromAddress = new MailAddress("*****@*****.**", "OCCG Support"); // var fromAddress = new MailAddress("*****@*****.**", "OCCG Support"); //2.The Destination email Addresses MailAddressCollection TO_addressList = new MailAddressCollection(); //3.Prepare the Destination email Addresses list foreach (var curr_address in Emails.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { MailAddress mytoAddress = new MailAddress(curr_address); TO_addressList.Add(mytoAddress); } var toAddress = new MailAddress(Emails); const string subject = "xyz for WE 8/27/2019"; using (var message = new MailMessage() { From = fromAddress, Subject = subject, Body = TextBody }) { //string ZippedFileToAttach = @"C:\pics\BA500_Assignment1"; string ZippedFileToAttach = @PathWhereToCopyTo + "\\myzip.zip"; //string ZippedFileToAttach = @"C:\Projects\myzip.zip"; //string ZippedFileToAttach = @"C:\Projects\myzip.zip"; message.Attachments.Add(new Attachment(ZippedFileToAttach)); message.To.Add(TO_addressList.ToString()); Myserver.Send(message); Console.WriteLine("Message sent to the emails provided."); } } catch (Exception ex) { } }
private static void FillMailCollection(List <string> sEmails, MailAddressCollection emails) { if (sEmails != null && emails != null) { foreach (string sEmail in sEmails) { if (!string.IsNullOrEmpty(sEmail)) { MailAddress mailAdress = new MailAddress(sEmail); emails.Add(mailAdress); } } } }
private static MailAddressCollection ObtenerDestinatarios(TipoDestinatario Tipo, Correo correo) { MailAddressCollection MAC = new MailAddressCollection(); try { string Lista = string.Empty; switch (Tipo) { case TipoDestinatario.Principal: Lista = correo.CORdestinatarios; break; //case TipoDestinatario.Copia: // Lista = correo.CORdestinatariosCopia; // break; //case TipoDestinatario.CopiaOculta: // Lista = correo.CORdestinatariosCopiaOculta; // break; default: Lista = correo.CORdestinatarios; break; } if (!string.IsNullOrEmpty(Lista)) { string[] Dest = Lista.Split(';'); foreach (string S in Dest) { if (!string.IsNullOrEmpty(S) && S.Split('<').Length > 1 && S.Split('"').Length > 1) { string Direccion = S.Split('<')[1].Replace('>', ' ').Trim(); string NombreMostrar = S.Split('"')[1].Trim(); MailAddress MA = new MailAddress(Direccion, NombreMostrar, Encoding.UTF8); MAC.Add(MA); } } } } catch (Exception exc) { new Exception("Error al obtener destinatario", exc); } return(MAC); }
private static void AddEmail2MailAddressCollection(List <string> eList, MailAddressCollection MC) { if (eList == null) { return; } foreach (string e in eList) { if (!string.IsNullOrEmpty(e)) { MC.Add(e); } } }
/// <summary>Converts the given object to the type of this converter, using the specified context and culture information.</summary> /// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture. </param> /// <param name="value">The <see cref="T:System.Object" /> to convert. </param> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string str = value as string; if (str == null) { return(base.ConvertFrom(context, culture, value)); } MailAddressCollection collection = new MailAddressCollection(); collection.Add(str); return(collection.Single()); }
private MailAddressCollection BuildAddressCollection(string emailValues) { var collection = new MailAddressCollection(); if (!string.IsNullOrEmpty(emailValues)) { var values = emailValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var value in values) { collection.Add(new MailAddress(value)); } } return(collection); }
/*******************************************************************************************************************************/ /* Elshiekh Code */ /*******************************************************************************************************************************/ //------------------------------------------ //Get mail address collection from string //------------------------------------------ public static void GetMailAddressCollectionFromCollectionString(string adressesString, MailAddressCollection collection) { if (!string.IsNullOrEmpty(adressesString)) { string[] addressesAray = adressesString.Split(new Char[] { ',' }); //clear previous list collection.Clear(); //add new items for (int i = 0; i < addressesAray.Length; i++) { collection.Add(addressesAray[i]); } } //return collection; }
public List <Address> GetList(string addresses) { var result = new List <Address>(); MailAddressCollection mailAddresses = new MailAddressCollection(); if (!string.IsNullOrEmpty(addresses)) { mailAddresses.Add(addresses); } foreach (var item in mailAddresses) { result.Add(new Address(item.Address, item.DisplayName)); } return(result); }
/// <summary> /// Render <paramref name="layout"/> and add the addresses to <paramref name="mailAddressCollection"/> /// </summary> /// <param name="mailAddressCollection">Addresses appended to this list</param> /// <param name="layout">layout with addresses, ; separated</param> /// <param name="logEvent">event for rendering the <paramref name="layout"/></param> /// <returns>added a address?</returns> private static bool AddAddresses(MailAddressCollection mailAddressCollection, Layout layout, LogEventInfo logEvent) { var added = false; if (layout != null) { foreach (string mail in layout.Render(logEvent).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { mailAddressCollection.Add(mail); added = true; } } return(added); }
// Получение коллекции адресов из строки private static MailAddressCollection GetAddressColection(string fullAddress) { string[] addresses = fullAddress.Split(','); MailAddressCollection adresCol = new MailAddressCollection(); foreach (string adress in addresses) { MailAddress temp = GetAddress(adress); if (temp != null) { adresCol.Add(temp); } } return(adresCol); }
/*/// <summary> * /// Emails the calendar event. * /// </summary> * /// <param name="location">The location.</param> * /// <param name="subject">The subject.</param> * /// <param name="body">The body.</param> * /// <param name="priority">The priority.</param> * /// <param name="busy">if set to <c>true</c> [busy].</param> * /// <param name="beginDate">The begin date.</param> * /// <param name="endDate">The end date.</param> * /// <param name="reminderTime">The reminder time.</param> * /// <param name="emailTo">The email to.</param> * public static void EmailICSCalendarEvent(string location, string subject, string body, int priority, bool busy, DateTime beginDate, DateTime endDate, int reminderTime, string emailTo) * { * using (MemoryStream ms = CalendarHelper.GenerateCalendarICSMemoryStream("Desk", "test", "bodytest", 3, true, DateTime.Now, DateTime.Now.AddHours(1), 15) as MemoryStream) * { * Emailer.SendMessage(emailTo, "", "test", "subject", "body", false, ".com", new List<Attachment> { new Attachment(ms, Guid.NewGuid() + ".ics") }); * } * }*/ /// <summary> /// Emails the calendar event. /// </summary> /// <param name="location">The location.</param> /// <param name="subject">The subject.</param> /// <param name="body">The body.</param> /// <param name="priority">The priority.</param> /// <param name="busy">if set to <c>true</c> [busy].</param> /// <param name="beginDate">The begin date.</param> /// <param name="endDate">The end date.</param> /// <param name="reminderTime">The reminder time.</param> /// <param name="emailTo">The email to.</param> /// <param name="emailFrom">The email from. </param> /// <param name="emailCc">The email CC. </param> /// <param name="inviteName"> Name of calendar event</param> public static void EmailIcsCalendarEvent(string location, string subject, string body, int priority, bool busy, DateTime beginDate, DateTime endDate, int reminderTime, string emailFrom, string emailTo, string emailCc, string inviteName) { using (var ms = CalendarHelper.GenerateCalendarIcsMemoryStream(location, subject, body, priority, true, beginDate, endDate, reminderTime) as MemoryStream) { var toEmailsList = new MailAddressCollection(); foreach (var email in emailTo.Split(';')) { toEmailsList.Add(new MailAddress(email)); } Emailer.SendGmailSupportMessage(toEmailsList, subject, body, new List <string> { inviteName + ".ics" }); } }
static void SendRegisterEmail(RegisterEmailViewModel items) { // access template // apply data to placeholder var template = Data.RegisterTemplate(); var subject = TemplateStringWithValue(template[1], GetPropertyValues(items)); var body = TemplateStringWithValue(template[0], GetPropertyValues(items)); var collection = new MailAddressCollection(); foreach (var email in items.Emails) { collection.Add(new MailAddress(email, email)); } Task.Factory.StartNew(() => new Email(EmailConfigBo, items.Emails, subject, body)); }
//TODO: move this to Utils class public static void InterceptEmail(MailMessage message, string testEmail) { //copy MailAddressCollection toAddresses = new MailAddressCollection(); foreach (MailAddress mailAddress in message.To) { MailAddress ma = new MailAddress(mailAddress.Address + "_test"); toAddresses.Add(ma); } //clear message.To.Clear(); //add foreach (MailAddress mailAddress in toAddresses) { if (mailAddress.Address.EndsWith("_test")) { message.To.Add(mailAddress); } } //copy MailAddressCollection ccAddresses = new MailAddressCollection(); foreach (MailAddress mailAddress in message.CC) { MailAddress ma = new MailAddress(mailAddress.Address + "_test"); ccAddresses.Add(ma); } //clear message.CC.Clear(); //add foreach (MailAddress mailAddress in ccAddresses) { if (mailAddress.Address.EndsWith("_test")) { message.CC.Add(mailAddress); } } string[] emails = testEmail.Split(';'); foreach (string address in emails) { message.To.Add(new MailAddress(address)); } }
public bool Post([FromBody] MailDto email) { try { MailMessage objmail = new MailMessage(); MailAddressCollection mails = new MailAddressCollection(); foreach (string mail in email.destinations) { mails.Add(new MailAddress(mail)); } objmail.Subject = "Appel D'Offres"; objmail.From = new MailAddress(email.author); foreach (string fi in email.documents) { Attachment fichier = new Attachment(fi); objmail.Attachments.Add(fichier); } foreach (MailAddress destinator in mails) { objmail.To.Add(destinator); } objmail.Body = "Code:" + email.offer.code + "<br/>" + "Intitule:" + email.offer.intitule + "<br/>" + "Libelle:" + email.offer.categorie.libelle + "<br/>" + "Description:" + email.offer.description + "<br/>" + "Date Limit:" + email.offer.dateLimit + "<br/>" + "Place Of Depot:" + email.offer.placeDepot; objmail.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", email.password); client.Send(objmail); return(true); } catch (Exception e) { Debug.WriteLine(e.Message + e.StackTrace); throw; } }
/// <summary> /// 解析分解邮件地址 /// </summary> /// <param name="mailAddress">邮件地址列表</param> /// <param name="mailAddressCollection">邮件地址对象</param> protected static void PaserMailAddress(List <string> mailAddress, MailAddressCollection mailAddressCollection) { if (mailAddress == null || mailAddress.Count == 0) { return; } foreach (var address in mailAddress) { if (address.Trim() == string.Empty) { continue; } mailAddressCollection.Add(new MailAddress(address)); } }
protected void AddAddresses(string addresses, MailAddressCollection mac) { if (addresses == null) { return; } string[] s = addresses.Split(_addressSeparator, StringSplitOptions.RemoveEmptyEntries); if (s != null) { for (int i = 0; i < s.Length; i++) { mac.Add(s[i]); } } }
public static MailAddressCollection GetEmailAddressCollection(string[] emails) { MailAddressCollection result = new MailAddressCollection(); if (emails == null || emails.Count() == 0) { return(result); } foreach (var email in emails) { result.Add(GetFullEmailAddress(email)); } return(result); }
/// <summary> /// Gets a collection of email addresses from an email recipient collection from a config file /// </summary> /// <param name="recipients"> /// </param> /// <returns> /// </returns> public static MailAddressCollection GetMailAddressCollection(EmailRecipientCollection recipients) { if (recipients == null) { throw new ArgumentNullException("recipients"); } var result = new MailAddressCollection(); foreach (EmailRecipient item in recipients) { result.Add(item.Value); } return result; }
/// <summary> /// Parses the comma delimited email addresses. /// </summary> /// <param name="emailAddresses">The email addresses.</param> /// <returns></returns> public static MailAddressCollection ParseEmailAddresses(string emailAddresses) { try { MailAddressCollection mailAddressCollection = new MailAddressCollection(); if (!string.IsNullOrEmpty(emailAddresses)) mailAddressCollection.Add(emailAddresses); return mailAddressCollection; } catch (FormatException e) { throw new FormatException("Error parsing email addresses: " + emailAddresses, e); } }
private void AddEmailAddressesFromString(MailAddressCollection collection, string text) { if (string.IsNullOrEmpty(text.Trim())) { return; } string[] list = text.Split('|'); foreach (string s in list) { MailAddress address = GetEmailAddressFromString(s); if (address != null) { collection.Add(address); } } }