private IEnumerable <System.Net.Mail.MailAddressCollection> GetEmailDestinationAddressesCollection( IEnumerable <IChannelIdentity> destinationIdentities, bool useSingleMessageForMultipleRecepients) { if (useSingleMessageForMultipleRecepients) { var mailAddressCollection = new System.Net.Mail.MailAddressCollection(); foreach (var destinationIdentity in destinationIdentities) { mailAddressCollection.Add(GetMailAddress(destinationIdentity)); } return(new System.Net.Mail.MailAddressCollection[] { mailAddressCollection }); } else { var mailAddressesSet = new List <System.Net.Mail.MailAddressCollection>(destinationIdentities.Count()); foreach (var destinationIdentity in destinationIdentities) { var mailAddressCollection = new System.Net.Mail.MailAddressCollection(); mailAddressCollection.Add(GetMailAddress(destinationIdentity)); mailAddressesSet.Add(mailAddressCollection); } return(mailAddressesSet); } }
private static void addAddressesToMailAddressCollection( IEnumerable <EmailAddress> emailAddressCollection, System.Net.Mail.MailAddressCollection mailAddressCollection) { foreach (var address in emailAddressCollection) { mailAddressCollection.Add(address.ToMailAddress()); } }
private void TryAddAddress(string email, string displayName, System.Net.Mail.MailAddressCollection col) { try { var a = new System.Net.Mail.MailAddress(email, displayName); col.Add(a); } catch (Exception ex) { log.Debug(ex.Message, ex); } }
static void HandleSmsRecievedEvent(object sender, Sms e) { //Neue SMS-Nachricht empfangen Gsm_Basics.RaiseGsmEvent(GsmEventArgs.Telegram.SmsRec, e.Message); //Neue Nachricht in DB speichern Sql.InsertMessageRec(e.Message, e.Phone); if (e.Message.Trim().ToLower() == GlobalProperty.SmsRouteTestTrigger.ToLower()) { //SMS mit 'MeldeAbruf' Empfangen //if (!Gsm.SmsSendQueue.Contains(e)) { //Gsm.SmsSend(e.Phone, e.Message + " um " + DateTime.Now); //Gsm.SmsToDelete.Add(e.Index); //Gsm.SmsDeletePending(); const string ctrlz = "\u001a"; //Senden Gsm_Basics.AddAtCommand("AT+CMGS=\"+" + e.Phone + "\"\r"); Gsm_Basics.AddAtCommand(e.Message + " um " + DateTime.Now + ctrlz); } } else { bool isBlocked = Sql.IsMessageBlockedNow(e.Message); if (isBlocked) { Sql.Log(MelBoxSql.LogTopic.Shift, MelBoxSql.LogPrio.Info, "Keine SMS: " + e.Message); } else { //Für jeden Empfänger (Bereitschaft) eine SMS vorbereiten foreach (ulong phone in Sql.GetCurrentShiftPhoneNumbers()) { //Nachricht per SMS weiterleiten Gsm.SmsSend(phone, e.Message); } } //Nachricht per email weiterleiten System.Net.Mail.MailAddressCollection mailTo = Sql.GetCurrentShiftEmail(); foreach (string mail in Email.PermanentEmailRecievers) { mailTo.Add(new System.Net.Mail.MailAddress(mail)); } Email.Send(mailTo, e, isBlocked); } Gsm.ReadGsmMemory(); }
static EmailUtilities() { Mapper.CreateMap <string, System.Net.Mail.MailAddress>() .ConvertUsing(emailAddress => null == emailAddress ? null : new System.Net.Mail.MailAddress(emailAddress)); Mapper.CreateMap <List <string>, System.Net.Mail.MailAddressCollection>().ConvertUsing( emailAddressList => { var mailAddressCollection = new System.Net.Mail.MailAddressCollection(); if (null != emailAddressList && emailAddressList.Any()) { mailAddressCollection.Add(string.Join(",", emailAddressList)); } return(mailAddressCollection); }); Mapper.CreateMap <Domain.Email.Models.Email, System.Net.Mail.MailMessage>() .ForMember(dest => dest.Body, opt => opt.MapFrom(src => src.Body)) .ForMember(dest => dest.From, opt => opt.MapFrom(src => src.FromAddress)) .ForMember(dest => dest.IsBodyHtml, opt => opt.MapFrom(src => src.IsContentHtml)) .ForMember(dest => dest.Subject, opt => opt.MapFrom(src => src.Subject)) .ForMember(dest => dest.To, opt => opt.MapFrom(src => src.ToAddresses)) .ForMember(dest => dest.Bcc, opt => opt.MapFrom(src => src.BCCAddresses)) .ForMember(dest => dest.CC, opt => opt.MapFrom(src => src.CCAddresses)); // Aspose... Mapper.CreateMap <AsposeMailAddress, string>() .ConvertUsing(emailAddress => null == emailAddress ? string.Empty : emailAddress.Address); Mapper.CreateMap <AsposeMailAddressCollection, List <string> >().ConvertUsing( mailAddressCollection => { var emailAddressList = new List <string>(); if (null != mailAddressCollection && mailAddressCollection.Any()) { emailAddressList.AddRange(mailAddressCollection.Select(Mapper.Map <string>)); } return(emailAddressList); }); Mapper.CreateMap <AsposeMailMessage, Domain.Email.Models.Email>() .ForMember(dest => dest.Body, opt => opt.MapFrom(src => src.Body)) .ForMember(dest => dest.FromAddress, opt => opt.MapFrom(src => src.From)) .ForMember(dest => dest.IsContentHtml, opt => opt.MapFrom(src => src.IsBodyHtml)) .ForMember(dest => dest.Subject, opt => opt.MapFrom(src => src.Subject)) .ForMember(dest => dest.ToAddresses, opt => opt.MapFrom(src => src.To)) .ForMember(dest => dest.BCCAddresses, opt => opt.MapFrom(src => src.Bcc)) .ForMember(dest => dest.CCAddresses, opt => opt.MapFrom(src => src.CC)) .ForMember(dest => dest.DateReceived, opt => opt.MapFrom(src => src.Date)); }
/// <summary> /// Erzeugt Einen EIntrag in der Nachrichten-Datenbank, Behandelt SMSAbruf-Test, sendet die Nachricht weiter an die aktuell eingeteilte Schicht. /// </summary> /// <param name="messages"></param> private void ProcessRecievedMessages(MessageCollection messages) { //Gsm gsm = new Gsm(); foreach (Message message in messages) { //Nachrichten in Datenbank schreiben uint newMsgId = sql.CreateMessageEntry(message); //Ist message eine Testnachricht? gsm.IsTestSmsRoute(message); if (!sql.IsMessageBlocked(message) && newMsgId != 0) { System.Net.Mail.MailAddressCollection mailAddresses = new System.Net.Mail.MailAddressCollection(); List <uint> sendSmsRecieverIds = new List <uint>(); List <uint> sendMailRecieverIds = new List <uint>(); //Nachrichten an Bereitschaft senden foreach (NightShift shift in sql.GetCurrentShifts()) { if (shift.SendViaSMS) { StatusBarText = "Sende SMS an +" + shift.SendToCellphone; if (shift.SendToCellphone > 0) { sendSmsRecieverIds.Add(sql.GetIdFromEntry("Persons", "Cellphone", shift.SendToCellphone.ToString())); gsm.SendSMS(shift.SendToCellphone, message.Content); //Status gesendet in die Datenbank schreiben. sql.UpdateSentMessageEntry(newMsgId, MessageType.SentToSms, sendSmsRecieverIds); } } if (shift.SendViaEmail) { StatusBarText = "Sende Email..."; sendMailRecieverIds.Add(sql.GetIdFromEntry("Persons", "Name", shift.GuardName)); if (HelperClass.IsValidEmailAddress(shift.SendToEmail)) { mailAddresses.Add(new System.Net.Mail.MailAddress(shift.SendToEmail, shift.GuardName)); SendEmail(mailAddresses, message.Content, message.Content); //Status gesendet in die Datenbank schreiben. sql.UpdateSentMessageEntry(newMsgId, MessageType.SentToEmail, sendMailRecieverIds); } } } } } //Neue Nachrichten anzeigen Timer_LastMessages = sql.GetLastMessagesForShow(); }
public System.Net.Mail.MailAddressCollection SqlSelectEmailAddresses(string query, Dictionary <string, object> args = null) { try { System.Net.Mail.MailAddressCollection mailTo = new System.Net.Mail.MailAddressCollection(); using (var connection = new SqliteConnection(DataSource)) { connection.Open(); var command = connection.CreateCommand(); #pragma warning disable CA2100 // Review SQL queries for security vulnerabilities command.CommandText = query; #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities if (args != null && args.Count > 0) { foreach (string key in args.Keys) { command.Parameters.AddWithValue(key, args[key]); } } using (var reader = command.ExecuteReader()) { while (reader.Read()) { //Lese Eintrag while (reader.Read()) { //Lese Eintrag string name = reader.GetString(0); string mail = reader.GetString(1); if (IsEmail(mail)) { mailTo.Add(new System.Net.Mail.MailAddress(mail, name)); } } } } } return(mailTo); } catch (Exception ex) { throw new Exception("SqlSelectEmailAddresses(): " + query + "\r\n" + ex.GetType() + "\r\n" + ex.Message); } }
/// <summary> /// متد ارسال که چهار پارامتر دارد /// در 99 درصد از ارسال رایانامه به این شکل میباشد /// </summary> /// <param name="recipient">دريافت کننده</param> /// <param name="subject">موضوع</param> /// <param name="body">بدنه</param> /// <param name="priority">اهميت</param> public static void Send ( System.Net.Mail.MailAddress recipient, string subject, string body, System.Net.Mail.MailPriority priority ) { System.Net.Mail.MailAddressCollection oRecipients = new System.Net.Mail.MailAddressCollection(); oRecipients.Add(recipient); Send(null, oRecipients, subject, body, priority, null, System.Net.Mail.DeliveryNotificationOptions.Never); }
public string _SendNextDayConfirmationEmail(DateTime? date) { var tomorrow = date ?? DateTime.Now.Date.AddDays(1); var reservations = db.Reservations.Include("Event").ToList().Where(r => r.startTime.Date == tomorrow); if (reservations != null) { JavaScriptSerializer s = new JavaScriptSerializer(); List<ReservationMailResult> results = new List<ReservationMailResult>(); string userEmail = Helpers.Helpers.GetEmailFromUser(User.Identity); foreach (var r in reservations.Where(r => !r.Options.Any(ro => ro.optionId == 6))) //do not send for Out of Order rooms { System.Net.Mail.MailAddressCollection to = new System.Net.Mail.MailAddressCollection(); to.Add(Helpers.Helpers.GetEmailFromUser(r.Event.organizer)); //to.Add("*****@*****.**"); System.Net.Mail.MailAddressCollection cc = new System.Net.Mail.MailAddressCollection(); cc.Add(userEmail); System.Net.Mail.MailAddressCollection bcc = new System.Net.Mail.MailAddressCollection(); bcc.Add("*****@*****.**"); string from = userEmail ?? "*****@*****.**"; string subject = String.Join(" | ", "EMS Reservation Confirmation: " + r.Event.name, r.startTime.ToShortDateString(), r.startTime.ToShortTimeString(), String.Join(", ", r.Locations.OrderBy(rl => rl.locationId).Select(rl => rl.name).Distinct()) ); string body = RenderViewToString(ControllerContext, "~/Views/Reservations/_ReservationConfirmationEmail.cshtml", r, true); Exception mailResult = Helpers.Helpers.SendEmail(from, to, cc, bcc, subject, true, body); ReservationMailResult mr = new ReservationMailResult(); if (mailResult.Message.ToString() != "success") { mr.Class = "warning"; mr.Message = mailResult.Message.ToString(); } else { mr.Class = "success"; mr.Message = "Your mail was sent successfully"; } mr.Recipient = Helpers.Helpers.GetUser(r.Event.organizer).shortName; mr.Details = subject; results.Add(mr); } return s.Serialize(results); //string body = RenderViewToString(ControllerContext, "~/Views/Shared/_ConfirmationEmail.cshtml", ev, true); } return string.Empty; }
/// <summary> /// Sendet ein Lebensbit zu bestimmtem Empfänger, wenn Voraussetzungen erfüllt sind. /// </summary> /// <param name="sender"></param> void MelBox2HeartBeat(object sender) { //Wenn größer 0, dann ist das zweite Datum später als das erste //Wenn letztes Mal + 1 Tag später ist als jetzt if (LastHeartBeat.AddDays(1).CompareTo(DateTime.Now) > 0) { return; } // gsm.SendSMS(4916095285304, "MelBox2 OK"); System.Net.Mail.MailAddressCollection addresses = new System.Net.Mail.MailAddressCollection(); addresses.Add(new System.Net.Mail.MailAddress("*****@*****.**", "HarmLifeBeatReciever")); MainWindow.SendEmail(addresses, "MelBox2 OK", "MelBox2 OK - gesendet um " + DateTime.Now.ToLongTimeString()); //Setze LastHeartBeat LastHeartBeat = DateTime.Now.Date.AddHours(8); // 8 Uhr morgens StatusBarText = "Lebenszeichen gesendet um " + DateTime.Now.ToShortTimeString(); }
private IEnumerable <IdentitiesToMailAddresses> GetIdentitiesToMailAddressesAssociations( IEnumerable <IChannelIdentity> destinationIdentities, bool useSingleMessageForMultipleRecepients) { if (useSingleMessageForMultipleRecepients) { var mailAddressCollection = new System.Net.Mail.MailAddressCollection(); foreach (var destinationIdentity in destinationIdentities) { mailAddressCollection.Add(GetMailAddress(destinationIdentity)); } return(new IdentitiesToMailAddresses[] { new IdentitiesToMailAddresses { ChannelIdentities = destinationIdentities, MailAddresses = mailAddressCollection } }); } else { var identitiesToMailAddressesSet = new List <IdentitiesToMailAddresses>(destinationIdentities.Count()); foreach (var destinationIdentity in destinationIdentities) { var mailAddressCollection = new System.Net.Mail.MailAddressCollection(); mailAddressCollection.Add(GetMailAddress(destinationIdentity)); identitiesToMailAddressesSet.Add(new IdentitiesToMailAddresses { MailAddresses = mailAddressCollection, ChannelIdentities = new IChannelIdentity[] { destinationIdentity } }); } return(identitiesToMailAddressesSet); } }
public string _SendConfirmationEmail(int? eventId, string body, string isAddOn) { //Int32 id = Convert.ToInt32(eventId); if (eventId != null) { var ev = db.Events.Include("Reservations").Where(e => e.eventId == eventId).FirstOrDefault(); if (ev != null) { bool addon = Convert.ToBoolean(isAddOn); string userEmail = Helpers.Helpers.GetEmailFromUser(User.Identity); JavaScriptSerializer s = new JavaScriptSerializer(); System.Net.Mail.MailAddressCollection to = new System.Net.Mail.MailAddressCollection(); to.Add(Helpers.Helpers.GetEmailFromUser(ev.organizer)); //to.Add("*****@*****.**"); if (addon) { to.Add("*****@*****.**"); } List<string> optionRecipients = new List<string>(); foreach (var reservation in ev.Reservations) { foreach (var option in reservation.Options) { foreach (var user in option.Users) { optionRecipients.Add(user.email); } } } foreach (var recipient in optionRecipients.Distinct()) { to.Add(recipient); } System.Net.Mail.MailAddressCollection cc = new System.Net.Mail.MailAddressCollection(); cc.Add(userEmail); System.Net.Mail.MailAddressCollection bcc = new System.Net.Mail.MailAddressCollection(); bcc.Add("*****@*****.**"); string from = userEmail ?? "*****@*****.**"; //string body = RenderViewToString(ControllerContext, "~/Views/Shared/_ConfirmationEmail.cshtml", ev, true); string subject = String.Join(" | ", "EMS Reservation Confirmation: " + ev.name, ev.startTime.ToShortDateString(), ev.startTime.ToShortTimeString(), String.Join(", ", ev.Locations.OrderBy(l => l.locationId).Select(el => el.name).Distinct())); subject = addon ? "Add On: " + subject : subject; Exception mailResult = Helpers.Helpers.SendEmail(from, to, cc, bcc, subject, true, body); MailResult r = new MailResult(); if (mailResult.Message.ToString() != "success") { r.Class = "warning"; r.Message = mailResult.Message.ToString(); } else { r.Class = "success"; r.Message = "Your mail was sent successfully"; } return s.Serialize(r); } } return string.Empty; }
public string _SendConfirmationEmail(int? reservationId, string body, string isAddOn, string[] recipients) { //Int32 id = Convert.ToInt32(reservationId); var reservation = db.Reservations.Include("Event").Where(r => r.reservationId == reservationId).FirstOrDefault(); if (reservation != null) { bool addon = Convert.ToBoolean(isAddOn); string userEmail = Helpers.Helpers.GetEmailFromUser(User.Identity); JavaScriptSerializer s = new JavaScriptSerializer(); System.Net.Mail.MailAddressCollection to = new System.Net.Mail.MailAddressCollection(); if (recipients != null && recipients.Length > 0) { foreach (var recipient in recipients) { to.Add(recipient); } } else { //to.Add(Helpers.Helpers.GetEmailFromUser(reservation.Event.organizer)); } //to.Add("*****@*****.**"); if (addon) { to.Add("*****@*****.**"); } List<string> optionRecipients = new List<string>(); foreach (var option in reservation.Options) { foreach (var user in option.Users) { optionRecipients.Add(user.email); } } foreach (var recipient in optionRecipients.Distinct()) { to.Add(recipient); } System.Net.Mail.MailAddressCollection cc = new System.Net.Mail.MailAddressCollection(); cc.Add(userEmail); System.Net.Mail.MailAddressCollection bcc = new System.Net.Mail.MailAddressCollection(); bcc.Add("*****@*****.**"); string from = userEmail ?? "*****@*****.**"; string subject = String.Join(" | ", "EMS Reservation Confirmation: " + reservation.Event.name, reservation.startTime.ToShortDateString(), reservation.startTime.ToShortTimeString(), String.Join(", ", reservation.Locations.OrderBy(rl => rl.locationId).Select(rl => rl.name).Distinct())); subject = addon ? "Add On: " + subject : subject; Exception mailResult = Helpers.Helpers.SendEmail(from, to, cc, bcc, subject, true, body); Result r = new Result(); if (mailResult.Message.ToString() != "success") { r.Class = "warning"; r.Message = mailResult.Message.ToString(); } else { r.Class = "success"; r.Message = "Your mail was sent successfully"; } return s.Serialize(r); } return string.Empty; }