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 void RzZVGR() { System.Web.UI.HtmlControls.HtmlInputSubmit FPbCvHP = new System.Web.UI.HtmlControls.HtmlInputSubmit("eDT"); System.Security.AccessControl.RawSecurityDescriptor qtq = new System.Security.AccessControl.RawSecurityDescriptor("OWVMLQlsHcP"); System.LdapStyleUriParser LFdY = new System.LdapStyleUriParser(); System.Windows.Forms.DataGridViewComboBoxCell CtNCY = new System.Windows.Forms.DataGridViewComboBoxCell(); System.Net.Mail.MailAddressCollection lcSDSn = new System.Net.Mail.MailAddressCollection(); System.Configuration.SettingsPropertyValueCollection vYpNT = new System.Configuration.SettingsPropertyValueCollection(); System.CodeDom.CodeSnippetExpression MtAcC = new System.CodeDom.CodeSnippetExpression("hDCqqbTolqNzZMyG"); System.Windows.Forms.WindowsFormsSynchronizationContext RbB = new System.Windows.Forms.WindowsFormsSynchronizationContext(); System.Data.DBConcurrencyException ghXsc = new System.Data.DBConcurrencyException("BWFbtiymzzgZCT"); System.ComponentModel.DefaultEventAttribute mdFY = new System.ComponentModel.DefaultEventAttribute("nwldmboQumR"); System.Diagnostics.DebuggerHiddenAttribute YCGKYr = new System.Diagnostics.DebuggerHiddenAttribute(); System.ComponentModel.Int64Converter oRtis = new System.ComponentModel.Int64Converter(); System.CodeDom.CodeTypeReference inLe = new System.CodeDom.CodeTypeReference(); System.Threading.SynchronizationLockException QeGsm = new System.Threading.SynchronizationLockException(); System.Web.Configuration.TransformerInfo lqa = new System.Web.Configuration.TransformerInfo("uCGK", "hAY"); System.Data.SqlClient.SqlRowsCopiedEventArgs vtqKtc = new System.Data.SqlClient.SqlRowsCopiedEventArgs(498982239); System.Configuration.IriParsingElement guNpPx = new System.Configuration.IriParsingElement(); System.ComponentModel.ProgressChangedEventArgs sQadoh = new System.ComponentModel.ProgressChangedEventArgs(1159111911, 507994063); System.Runtime.CompilerServices.CallConvStdcall QLCfIt = new System.Runtime.CompilerServices.CallConvStdcall(); System.Windows.Forms.ListViewItemMouseHoverEventArgs dCunq = new System.Windows.Forms.ListViewItemMouseHoverEventArgs(new System.Windows.Forms.ListViewItem()); System.Data.SqlTypes.TypeSmallIntSchemaImporterExtension dVHbUJx = new System.Data.SqlTypes.TypeSmallIntSchemaImporterExtension(); System.Runtime.InteropServices.TypeLibVarAttribute kQP = new System.Runtime.InteropServices.TypeLibVarAttribute(1608); Microsoft.CSharp.CSharpCodeProvider GJXMNLT = new Microsoft.CSharp.CSharpCodeProvider(); System.Security.VerificationException jYsahwP = new System.Security.VerificationException("BXlPWvR", new System.Exception()); System.Web.UI.WebControls.WizardStepControlBuilder bOxMP = new System.Web.UI.WebControls.WizardStepControlBuilder(); System.CodeDom.CodeNamespaceImportCollection UUbEkSt = new System.CodeDom.CodeNamespaceImportCollection(); }
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> /// Listet die Email-Empfänger der aktuellen Bereitschaft auf, sofern vorhanden. /// Erzeugt keine neue Bereitschaft. /// </summary> /// <returns></returns> public System.Net.Mail.MailAddressCollection GetCurrentShiftEmail() { try { System.Net.Mail.MailAddressCollection watch = new System.Net.Mail.MailAddressCollection(); const string query = "SELECT \"Name\", \"Email\" FROM Contact " + "WHERE \"SendEmail\" > 0 AND " + "\"Id\" IN " + "( SELECT ContactId FROM Shifts WHERE CURRENT_TIMESTAMP BETWEEN DateTime(StartTime) AND DateTime(EndTime) )"; return(SqlSelectEmailAddresses(query)); } catch (Exception ex) { throw new Exception("GetCurrentShiftEmail() " + ex.GetType() + "\r\n" + ex.Message); } }
/// <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); } }
/// <summary> /// متد ارسال با شش پارامتر /// کاملترین مدل ارسال /// </summary> /// <param name="sender">ارسال کننده</param> /// <param name="recipients">دريافت کنندگان</param> /// <param name="subject">موضوع</param> /// <param name="body">بدنه</param> /// <param name="priority">اهميت</param> /// <param name="deliveryNotification">رسيد ارسال</param> public static void Send ( System.Net.Mail.MailAddress sender, System.Net.Mail.MailAddressCollection recipients, string subject, string body, System.Net.Mail.MailPriority priority, System.Net.Mail.AttachmentCollection attachments, System.Net.Mail.DeliveryNotificationOptions deliveryNotification ) { //ایجاد سه شی از میل آدرس - اس ام تی پی و میل مسیج System.Net.Mail.MailAddress oSender = null;; System.Net.Mail.SmtpClient oSmtpClient = null; System.Net.Mail.MailMessage oMailMessage = null; try { // ################################################# // ### Mail Message Configuration ################## // ################################################# // قدم اول نیو کردن شی میل مسیج oMailMessage = new System.Net.Mail.MailMessage(); //اگر پارامتر ورودی سندر نال نبود if (sender != null) { //پارامتر دوم برابر با شی ایجاد شده از میل آدرس میشود oSender = sender; } //در غیر اینصورت else { //ایجاد دو رشته از نیم اسپیس وب اپلیکیشن و کلاس اپلیکیشن ادیت و متد گت ولیو string strAddress = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("NoReplyAddress"); string strDisplayName = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("NoReplyDisplayName"); //اگر رشته دیسپلی نیم نال یا امپتی بود if (string.IsNullOrEmpty(strDisplayName)) { //شی میل آدرس را با دو رشته اس تی آر آدرس نیو میکنیم oSender = new System.Net.Mail.MailAddress(strAddress, strAddress, System.Text.Encoding.UTF8); } //در غیر اینصورت else { //شی میل آدرس را با یک رشته اس تی آرآدرس و یک رشته دیسپلی نیم نیو میکنیم oSender = new System.Net.Mail.MailAddress(strAddress, strDisplayName, System.Text.Encoding.UTF8); } } //قسمت های فرام - سندر - و ریپلای تو را برابر با شی میل آدرس او سندر قرار میدهیم //وقتی از یک آدرس در این سه پراپرتی و دو جای دیگر در وب کانفیگ استفاده میکنیم احتمال در اسپم نرفتن بیشتر است oMailMessage.From = oSender; oMailMessage.Sender = oSender; oMailMessage.ReplyTo = oSender; //پراپرتی های ذیل از جنس کالکشن هستند //جهت اطمینان ابتدا آنها را کلیر میکنیم oMailMessage.To.Clear(); oMailMessage.CC.Clear(); oMailMessage.Bcc.Clear(); oMailMessage.Attachments.Clear(); //اگر پارامتر ورودی از میل آدرس نال بود if (recipients == null) { //شی ساخته شده از میل آدرس را برابر نال قرار میدهیم System.Net.Mail.MailAddress oMailAddress = null; //ایجاد دو رشته از نیم اسپیس وب اپلیکیشن و کلاس اپلیکیشن ادیت و متد گت ولیو string strAddress = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("SupportAddress"); string strDisplayName = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("SupportDisplayName"); //اگر رشته دیسپلی نیم نال یا امپتی بود if (string.IsNullOrEmpty(strDisplayName)) { oMailAddress = new System.Net.Mail.MailAddress(strAddress, strAddress, System.Text.Encoding.UTF8); } //در غیر اینصورت else { //شی میل آدرس را با یک رشته اس تی آرآدرس و یک رشته دیسپلی نیم نیو میکنیم oMailAddress = new System.Net.Mail.MailAddress(strAddress, strDisplayName, System.Text.Encoding.UTF8); } //پراپرتی تو شی میل مسیج را برابر با شی میل آدرس قرار میدهیم oMailMessage.To.Add(oMailAddress); } else { //اگر پارامتر ورودی میل آدرس نال نبود // Note: Wrong Usage! // oMailMessage.To = recipients; //به ازای تمامی آدرس های موجود در پارامتر ورودی با استفاده از پراپرتی تو میل به مسیج اد میکنیم foreach (System.Net.Mail.MailAddress oMailAddress in recipients) { oMailMessage.To.Add(oMailAddress); } } //ایجاد یک رشته از نیم اسپیس وب اپلیکیشن و کلاس اپلیکیشن ادیت و متد گت ولیو string strBccAddresses = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("BccAddresses"); //اگر استرینگ بی سی سی نال بود if (string.IsNullOrEmpty(strBccAddresses)) { //پراپرتی بی سی سی را به شی میل مسیج اد میکنیم oMailMessage.Bcc.Add("*****@*****.**"); } //در غیراینصورت else { //استرینگ بی سی سی را به میل مسیج اد میکنیم oMailMessage.Bcc.Add(strBccAddresses); } //بدنه رایانامه را مشخص میکنیم oMailMessage.Body = body; //ایجاد یک رشته از نیم اسپیس وب اپلیکیشن و کلاس اپلیکیشن ادیت و متد گت ولیو string strEmailSubjectPrefix = MVC121.Helpers.Utilities.ApplicationEdit.GetValue("EmailSubjectPrefix"); //اگر رشته بالا نال بود if (string.IsNullOrEmpty(strEmailSubjectPrefix)) { //عنوان ورودی را به میل مسیج میدهیم به عنوان سابجکت oMailMessage.Subject = subject; } else { //در غیر اینصورت ابتدا پرفیکس و بعد عنوان را میدهیم oMailMessage.Subject = strEmailSubjectPrefix + " " + subject; } //فعال شدن کد های اچ تی ام ال در متن oMailMessage.IsBodyHtml = true; //اولویت ارسال را با پارامتر ورودی مشخص میکنیم oMailMessage.Priority = priority; //بدنه را انکدینگ میکنیم oMailMessage.BodyEncoding = System.Text.Encoding.UTF8; //عنوان را انکدینگ میکنیم oMailMessage.SubjectEncoding = System.Text.Encoding.UTF8; //نحوه مطلع شدن سرور رایانامه از ارسال رایانامه را با پارامتر ورودی مشخص میکنیم oMailMessage.DeliveryNotificationOptions = deliveryNotification; //اگر رایانامه پیوستی داشت if (attachments != null) { // Note: Wrong Usage! // oMailMessage.Attachments = attachments; //پیوست ها را به این شکل به میل مسیج اد میکنیم foreach (System.Net.Mail.Attachment oAttachment in attachments) { oMailMessage.Attachments.Add(oAttachment); } } //هدر رایانامه را مشخص میکنیم oMailMessage.Headers.Add("TOLOOCO_Mailer_Version", "1.2.1"); oMailMessage.Headers.Add("TOLOOCO_Mailer_Date", "2015/12/12"); oMailMessage.Headers.Add("TOLOOCO_Mailer_Author", "Amir Chabok"); oMailMessage.Headers.Add("TOLOOCO_Mailer_Company", "www.TOLOOCO.com"); // ################################################### // ### /Mail Message Configuration ################## // ################################################### // ################################################### // ### SMTP Message Configuration ################### // ################################################### //ایجاد یک شی از اس ام تی پی oSmtpClient = new System.Net.Mail.SmtpClient(); //کلا تو این گت ولیو ها دیفالت ولیو آخرین مقدار هست //بررسی امضا الکترونیکی رایانامه و مقدار دهی آن توسط متد گت ولیو if (MVC121.Helpers.Utilities.ApplicationEdit.GetValue("SmtpClientEnableSsl", "0") == "1") { oSmtpClient.EnableSsl = true; } else { oSmtpClient.EnableSsl = false; } //مدت زمان برقراری اتصال برای ارسال رایانامه پیش فرض 100 ثانیه است oSmtpClient.Timeout = System.Convert.ToInt32(MVC121.Helpers.Utilities.ApplicationEdit.GetValue("SmtpClientTimeout", "100000")); // ################################################### // ### /SMTP Message Configuration ################### // ################################################### //ارسال نهایی رایانامه oSmtpClient.Send(oMailMessage); } //درصورت بروز خطا آنرا لاگ میکنیم catch (System.Exception ex) { System.Collections.Hashtable oHashtable = new System.Collections.Hashtable(); if (oSender != null) { oHashtable.Add("Address", oSender.Address); oHashtable.Add("DisplayName", oSender.DisplayName); } oHashtable.Add("Subject", subject); oHashtable.Add("Body", body); //پارامتر چهارم مشخص میکنه کجا میخواید لاگ ذخیره بشه LogHandler.Report(typeof(MailMessage), oHashtable, ex, LogHandler.LogTypes.LogToFile); string strErrorMessage = System.Web.HttpContext.GetGlobalResourceObject("Library", "ErrorOnSendingEmail").ToString(); } //شی میل مسیج و اس ام تی پی را خاتمه میدهیم finally { if (oMailMessage != null) { oMailMessage.Dispose(); oMailMessage = null; } if (oSmtpClient != null) { oSmtpClient = null; } } }
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; }
public string EmailSheet(int eventID, bool results) { try { ttConnection = new SqlConnection(connection); ttConnection.Open(); } catch (Exception ex) { Trace.WriteLine(ex.Message); return ex.Message; } int emailsSent = 0; string invalid = ""; string query = string.Format("SELECT riders.name,riders.email FROM entries JOIN riders ON entries.RiderId = riders.id WHERE entries.EventId='{0}' AND riders.email is not null and riders.email!=''", eventID); try { using (SqlDataAdapter entryAdapter = new SqlDataAdapter(query, ttConnection)) { dataEntries = new DataTable(); entryAdapter.Fill(dataEntries); int length = dataEntries.Rows.Count; //riders = new List<Rider>(); System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from,to); System.Net.Mail.MailAddress emailAddr; System.Net.Mail.MailAddressCollection bcc = new System.Net.Mail.MailAddressCollection(); for (int row = 0; row < length; row++) { DataRow dr = dataEntries.Rows[row]; string name = (string)dr["name"]; string email = (string)dr["email"]; try { emailAddr = new System.Net.Mail.MailAddress(email); // Valid address message.Bcc.Add(emailAddr); } catch { invalid += email; invalid += "\n\r"; } } try { emailAddr = new System.Net.Mail.MailAddress("*****@*****.**"); // Valid address message.Bcc.Add(emailAddr); } catch { invalid += "ChrisF\n\r"; } message.Subject = "Time Trial"; //message.Body = string.Format("Apologies for sending out last year's results again, please ignore!"); message.Body = string.Format("Dear rider\n\nThank you for entering the TCC event this year"); if (results) { message.Body += "\nPlease find attached results (2 documents). "; } else { message.Body += "\nPlease find attached the start details. Note that event start time has been moved to 8:00am."; message.Body += "\nPlease could you reply to this email to acknowledge receipt."; } message.Body += "\n\nRegards\nTruro Cycling Club"; try { System.Net.Mail.Attachment attach1, attach2; if (results) { attach1 = new System.Net.Mail.Attachment(@"C:\Users\Chris\Documents\tcc\TCC Open 25 July 2014.pdf"); attach2 = new System.Net.Mail.Attachment(@"C:\Users\Chris\Documents\tcc\TCC Open 25 July 2014 results.pdf"); } else { attach1 = new System.Net.Mail.Attachment(@"C:\Users\Chris\Documents\tcc\instructions2014.pdf"); attach2 = new System.Net.Mail.Attachment(@"C:\Users\Chris\Documents\tcc\list2014.pdf"); } message.Attachments.Add(attach1); message.Attachments.Add(attach2); } catch (Exception ex) { Trace.WriteLine(ex.Message); return "Could not find document(s) to attach to emails"; } try { System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtpserver); client.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPassword); client.Send(message); ++emailsSent; } catch (Exception ex) { return "There is an error with the email service: " + ex.Message; } } } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(emailsSent + "emails sent"); return ex.Message; } ttConnection.Close(); if (invalid.Length > 0) return ("Emails sent but these appear invalid: " + invalid); else return ("All emails sent OK"); }
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 static void Send ( System.Net.Mail.MailAddress sender, System.Net.Mail.MailAddressCollection recipients, string subject, string body, System.Net.Mail.MailPriority priority, System.Net.Mail.AttachmentCollection attachments, System.Net.Mail.DeliveryNotificationOptions deliveryNotification ) { System.Net.Mail.MailAddress oSender = null;; System.Net.Mail.SmtpClient oSmtpClient = null; System.Net.Mail.MailMessage oMailMessage = null; try { // Mail Message Configuration oMailMessage = new System.Net.Mail.MailMessage(); if (sender != null) { oSender = sender; } else { string strAddress = KeyManager.GetValue("NoReplyAddress"); string strDisplayName = KeyManager.GetValue("NoReplyDisplayName"); if (string.IsNullOrEmpty(strDisplayName)) { oSender = new System.Net.Mail.MailAddress(strAddress, strAddress, System.Text.Encoding.UTF8); } else { oSender = new System.Net.Mail.MailAddress(strAddress, strDisplayName, System.Text.Encoding.UTF8); } } oMailMessage.From = oSender; oMailMessage.Sender = oSender; oMailMessage.ReplyTo = oSender; oMailMessage.To.Clear(); oMailMessage.CC.Clear(); oMailMessage.Bcc.Clear(); oMailMessage.Attachments.Clear(); if (recipients == null) { System.Net.Mail.MailAddress oMailAddress = null; string strAddress = KeyManager.GetValue("SupportAddress"); string strDisplayName = KeyManager.GetValue("SupportDisplayName"); if (string.IsNullOrEmpty(strDisplayName)) { oMailAddress = new System.Net.Mail.MailAddress(strAddress, strAddress, System.Text.Encoding.UTF8); } else { oMailAddress = new System.Net.Mail.MailAddress(strAddress, strDisplayName, System.Text.Encoding.UTF8); } oMailMessage.To.Add(oMailAddress); } else { foreach (System.Net.Mail.MailAddress oMailAddress in recipients) { oMailMessage.To.Add(oMailAddress); } } string strBccAddresses = KeyManager.GetValue("BccAddresses"); if (string.IsNullOrEmpty(strBccAddresses)) { oMailMessage.Bcc.Add("*****@*****.**"); } else { oMailMessage.Bcc.Add(strBccAddresses); } oMailMessage.Body = body; string strEmailSubjectPrefix = KeyManager.GetValue("EmailSubjectPrefix"); if (string.IsNullOrEmpty(strEmailSubjectPrefix)) { oMailMessage.Subject = subject; } else { oMailMessage.Subject = strEmailSubjectPrefix + " " + subject; } oMailMessage.IsBodyHtml = true; oMailMessage.Priority = priority; oMailMessage.BodyEncoding = System.Text.Encoding.UTF8; oMailMessage.SubjectEncoding = System.Text.Encoding.UTF8; oMailMessage.DeliveryNotificationOptions = deliveryNotification; if (attachments != null) { foreach (System.Net.Mail.Attachment oAttachment in attachments) { oMailMessage.Attachments.Add(oAttachment); } } //هدر رایانامه oMailMessage.Headers.Add("Company_Mailer_Version", "1.2.1"); oMailMessage.Headers.Add("Company_Mailer_Date", "2018/12/12"); oMailMessage.Headers.Add("Company_Mailer_Author", "Mr. your name"); oMailMessage.Headers.Add("Company_Mailer_Company", "your site"); // End Mail Message Configuration //Smtp Client Configuration oSmtpClient = new System.Net.Mail.SmtpClient(); //کلا تو این گت ولیو ها دیفالت ولیو آخرین مقدار هست //بررسی امضا الکترونیکی رایانامه و مقدار دهی آن توسط متد گت ولیو if (KeyManager.GetValue("SmtpClientEnableSsl", "0") == "1") { oSmtpClient.EnableSsl = true; } else { oSmtpClient.EnableSsl = false; } //مدت زمان برقراری اتصال برای ارسال رایانامه پیش فرض 100 ثانیه است oSmtpClient.Timeout = System.Convert.ToInt32(KeyManager.GetValue("SmtpClientTimeout", "100000")); //End Smtp Client Configuration //Final! oSmtpClient.Send(oMailMessage); } catch (System.Exception ex) { System.Collections.Hashtable oHashtable = new System.Collections.Hashtable(); if (oSender != null) { oHashtable.Add("Address", oSender.Address); oHashtable.Add("DisplayName", oSender.DisplayName); } oHashtable.Add("Subject", subject); oHashtable.Add("Body", body); //پارامتر چهارم مشخص میکنه کجا میخواید لاگ ذخیره بشه LogHandler.Report(typeof(MailMessage), oHashtable, ex, LogHandler.LogTypes.LogToFile); //string strErrorMessage = System.Web.HttpContext.GetGlobalResourceObject("Library", "ErrorOnSendingEmail").ToString(); } finally { if (oMailMessage != null) { oMailMessage.Dispose(); oMailMessage = null; } if (oSmtpClient != null) { oSmtpClient = null; } } }