private void btSendOne_Click(object sender, EventArgs e) { Encoding encoding = Encoding.GetEncoding((int)((CodePages)cbEncoding.SelectedItem)); List <string> attach = new List <string>(); foreach (var a in lbAttachments.Items) { attach.Add(Convert.ToString(a)); } sendMail = new SendMail(); sendMail.smtpServer = tbSMTPServer.Text; sendMail.from = tbMailFrom.Text; sendMail.username = tbSMTP_username.Text; sendMail.password = tbSMTP_password.Text; sendMail.port = Convert.ToInt32(tbSMTPPort.Text); sendMail.useSSL = chUseSSL.Checked; System.Net.Mail.MailPriority prior = (System.Net.Mail.MailPriority)cbPriority.SelectedItem; lbAlert.Text = ""; if (!sendMail.Send(tbOneMail.Text, tbCaption.Text, meBody.Text, chAsHtml.Checked, prior, encoding, chSimulate.Checked, true, attach.ToArray())) { if (!chIgnoreErrors.Checked) { timer1.Enabled = false; } lbAlert.Text = "Ошибка отправки: " + tbOneMail.Text; } }
async void btnSendEMail_Clicked(object sender, EventArgs e) { try { string senderAddress = "*****@*****.**"; var r = await Acr.UserDialogs.UserDialogs.Instance.PromptAsync(new Acr.UserDialogs.PromptConfig() { Title = "请输入密码", Message = $"请输入邮箱 {senderAddress} 密码", OkText = "确认", CancelText = "取消" }); if (r.Ok == false) { return; } string password = r.Text; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.EnableSsl = false; smtp.Host = "smtp.qiye.163.com"; smtp.Port = 25; // smtp.UseDefaultCredentials = true; // 与 PC 的 DBAutoBackup 不同点, Xamarin.Android 运行这句会报错, 注释后能正常发送邮件 smtp.Credentials = new System.Net.NetworkCredential(senderAddress, password); List <string> receive = new List <string>() { "*****@*****.**" // senderAddress }; System.Net.Mail.MailPriority mailPriority = System.Net.Mail.MailPriority.Normal; string subject = "Xamarin.Forms 发送邮件测试"; string content = $"发送邮件测试{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}"; mailPriority = System.Net.Mail.MailPriority.Normal; List <string> attachmentPathList = new List <string>(); new Util.EMailUtils().SendEMail ( sender: senderAddress, smtp: smtp, receiverList: receive, subject: subject, content: content, attachmentPathList: attachmentPathList, mailPriority: mailPriority ); } catch (Exception ex) { await DisplayAlert(title : "捕获错误", message : ex.GetFullInfo(), cancel : "确定"); } }
public static MailPriority Cast(this System.Net.Mail.MailPriority priority) { switch (priority) { case System.Net.Mail.MailPriority.High: return MailPriority.High; case System.Net.Mail.MailPriority.Low: return MailPriority.Low; case System.Net.Mail.MailPriority.Normal: return MailPriority.Normal; default: throw new InvalidOperationException(); } }
private System.Net.Mail.MailPriority GetMessagePriority(Growl.Connector.Priority priority) { System.Net.Mail.MailPriority messagePriority = System.Net.Mail.MailPriority.Normal; if (priority == Growl.Connector.Priority.Emergency) { messagePriority = System.Net.Mail.MailPriority.High; } else if (priority == Growl.Connector.Priority.VeryLow) { messagePriority = System.Net.Mail.MailPriority.Low; } return(messagePriority); }
/// <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 void TestSendEMail() { string pa = Console.ReadLine(); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.EnableSsl = false; smtp.Host = "smtp.qiye.163.com"; smtp.Port = 25; smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", pa); List <string> receive = new List <string>() { "*****@*****.**" }; System.Net.Mail.MailPriority mailPriority = System.Net.Mail.MailPriority.Normal; string subject = "Xamarin.Forms 发送邮件测试"; string content = $"发送邮件测试{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}"; mailPriority = System.Net.Mail.MailPriority.Normal; List <string> attachmentPathList = new List <string>(); //new Util.EMailUtils().SendEMail //( // sender: "*****@*****.**", // smtp: smtp, // receiverList: receive, // subject: subject, // content: content, // attachmentPathList: attachmentPathList, // mailPriority: mailPriority //); }
/// <summary> /// 优先级格式化 /// </summary> /// <param name="priority"></param> /// <returns></returns> public static string PriorityFormat(System.Net.Mail.MailPriority priority) { int priority2 = 0; switch (priority) { case System.Net.Mail.MailPriority.High: priority2 = 1; break; case System.Net.Mail.MailPriority.Low: priority2 = 5; break; case System.Net.Mail.MailPriority.Normal: priority2 = 3; break; default: priority2 = 3; break; } return(string.Format("X-Priority:{0}", priority2)); }
private void btFolderSend_Click(object sender, EventArgs e) { sendMail = new SendMail(); sendMail.smtpServer = tbSMTPServer.Text; sendMail.from = tbMailFrom.Text; sendMail.username = tbSMTP_username.Text; sendMail.password = tbSMTP_password.Text; sendMail.port = Convert.ToInt32(tbSMTPPort.Text); sendMail.useSSL = chUseSSL.Checked; string[] emailsfolders = Directory.GetDirectories(tbFolderName.Text).Where(f => SendMail.ValidateEmail(f)).ToArray(); AfterSendActions asa = (AfterSendActions)cbAfterSend.SelectedItem; Encoding encoding = Encoding.GetEncoding((int)((CodePages)cbEncoding.SelectedItem)); System.Net.Mail.MailPriority prior = (System.Net.Mail.MailPriority)cbPriority.SelectedItem; foreach (string folder in emailsfolders) { string mail = folder.Split(Path.DirectorySeparatorChar).Last(); sendMail.SendFolder(mail, folder, tbFolderName.Text, chSendAsArc.Checked, asa, tbCaption.Text, meBody.Text, chAsHtml.Checked, prior, encoding, chSimulateFolder.Checked, chSendAsArc.Checked); } }
private static string SendMail(bool SendAsync, string DefaultConnection, string MailFrom, string MailTo, string MailToDisplayName, string Cc, string Bcc, string ReplyTo, string Header, System.Net.Mail.MailPriority Priority, string Subject, Encoding BodyEncoding, string Body, string[] Attachment, string SMTPServer, string SMTPAuthentication, string SMTPUsername, string SMTPPassword, bool SMTPEnableSSL) { string strSendMail = ""; GeneralSettings GeneralSettings = new GeneralSettings(DefaultConnection); // SMTP server configuration if (SMTPServer == "") { SMTPServer = GeneralSettings.SMTPServer; if (SMTPServer.Trim().Length == 0) { return("Error: Cannot send email - SMTPServer not set"); } } if (SMTPAuthentication == "") { SMTPAuthentication = GeneralSettings.SMTPAuthendication; } if (SMTPUsername == "") { SMTPUsername = GeneralSettings.SMTPUserName; } if (SMTPPassword == "") { SMTPPassword = GeneralSettings.SMTPPassword; } MailTo = MailTo.Replace(";", ","); Cc = Cc.Replace(";", ","); Bcc = Bcc.Replace(";", ","); System.Net.Mail.MailMessage objMail = null; try { System.Net.Mail.MailAddress SenderMailAddress = new System.Net.Mail.MailAddress(MailFrom, MailFrom); System.Net.Mail.MailAddress RecipientMailAddress = new System.Net.Mail.MailAddress(MailTo, MailToDisplayName); objMail = new System.Net.Mail.MailMessage(SenderMailAddress, RecipientMailAddress); if (Cc != "") { objMail.CC.Add(Cc); } if (Bcc != "") { objMail.Bcc.Add(Bcc); } if (ReplyTo != string.Empty) { objMail.ReplyToList.Add(new System.Net.Mail.MailAddress(ReplyTo)); } objMail.Priority = (System.Net.Mail.MailPriority)Priority; objMail.IsBodyHtml = IsHTMLMail(Body); objMail.Headers.Add("In-Reply-To", $"ADefHelpDesk-{Header}"); foreach (string myAtt in Attachment) { if (myAtt != "") { objMail.Attachments.Add(new System.Net.Mail.Attachment(myAtt)); } } // message objMail.SubjectEncoding = BodyEncoding; objMail.Subject = Subject.Trim(); objMail.BodyEncoding = BodyEncoding; System.Net.Mail.AlternateView PlainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Utility.ConvertToText(Body), null, "text/plain"); objMail.AlternateViews.Add(PlainView); //if body contains html, add html part if (IsHTMLMail(Body)) { System.Net.Mail.AlternateView HTMLView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, null, "text/html"); objMail.AlternateViews.Add(HTMLView); } } catch (Exception objException) { // Problem creating Mail Object strSendMail = MailTo + ": " + objException.Message; // Log Error to the System Log Log.InsertSystemLog(DefaultConnection, Constants.EmailError, "", strSendMail); } if (objMail != null) { // external SMTP server alternate port int?SmtpPort = null; int portPos = SMTPServer.IndexOf(":"); if (portPos > -1) { SmtpPort = Int32.Parse(SMTPServer.Substring(portPos + 1, SMTPServer.Length - portPos - 1)); SMTPServer = SMTPServer.Substring(0, portPos); } System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); if (SMTPServer != "") { smtpClient.Host = SMTPServer; smtpClient.Port = (SmtpPort == null) ? (int)25 : (Convert.ToInt32(SmtpPort)); switch (SMTPAuthentication) { case "": case "0": // anonymous break; case "1": // basic if (SMTPUsername != "" & SMTPPassword != "") { smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential(SMTPUsername, SMTPPassword); } break; case "2": // NTLM smtpClient.UseDefaultCredentials = true; break; } } smtpClient.EnableSsl = SMTPEnableSSL; try { if (SendAsync) // Send Email using SendAsync { // Set the method that is called back when the send operation ends. smtpClient.SendCompleted += SmtpClient_SendCompleted; // Send the email DTOMailMessage objDTOMailMessage = new DTOMailMessage(); objDTOMailMessage.DefaultConnection = DefaultConnection; objDTOMailMessage.MailMessage = objMail; smtpClient.SendAsync(objMail, objDTOMailMessage); strSendMail = ""; } else // Send email and wait for response { smtpClient.Send(objMail); strSendMail = ""; // Log the Email LogEmail(DefaultConnection, objMail); objMail.Dispose(); smtpClient.Dispose(); } } catch (Exception objException) { // mail configuration problem if (!(objException.InnerException == null)) { strSendMail = string.Concat(objException.Message, Environment.NewLine, objException.InnerException.Message); } else { strSendMail = objException.Message; } // Log Error to the System Log Log.InsertSystemLog(DefaultConnection, Constants.EmailError, "", strSendMail); } } return(strSendMail); }
public void SendMail(string strErrorMessage) { string sender = "*****@*****.**"; string recipient = "*****@*****.**"; string copyRecipient = ""; string blindCopyRecipient = ""; System.Net.Mail.MailPriority MailPriority = System.Net.Mail.MailPriority.Normal; string strMachineInfo = "Machine: " + System.Environment.MachineName; strMachineInfo += System.Environment.NewLine; strMachineInfo += "Domain: " + System.Environment.UserDomainName; strMachineInfo += System.Environment.NewLine; strMachineInfo += "User: "******"Time: " + System.DateTime.Now.ToString("dddd, dd.MM.yyyy HH:mm:ss"); strMachineInfo += System.Environment.NewLine; strMachineInfo += "Bitness: " + (System.IntPtr.Size * 8).ToString(); strMachineInfo += System.Environment.NewLine; strMachineInfo += "OS: " + System.Environment.OSVersion.ToString(); strMachineInfo += System.Environment.NewLine; strMachineInfo += "CLR Version: " + System.Environment.Version.ToString(); strMachineInfo += System.Environment.NewLine; strMachineInfo += System.Environment.NewLine; strMachineInfo += System.Environment.NewLine; strErrorMessage = strMachineInfo + strErrorMessage; System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.Priority = MailPriority; mail.From = new System.Net.Mail.MailAddress(sender); mail.To.Add(recipient); if (copyRecipient.Length > 0) { mail.CC.Add(copyRecipient); } if (blindCopyRecipient.Length > 0) { mail.Bcc.Add(blindCopyRecipient); } string strAssemblyName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location); mail.Subject = strAssemblyName + " Error"; mail.Body = strErrorMessage; mail.IsBodyHtml = false; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; if (!string.IsNullOrEmpty(Logging.LogFilePath)) { if (System.IO.File.Exists(Logging.LogFilePath)) { System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(Logging.LogFilePath); mail.Attachments.Add(attach); } // End if (System.IO.File.Exists(Logging.LogFilePath)) } // End if (!string.IsNullOrEmpty(Logging.LogFilePath)) //mail.ReplyTo = New System.Net.Mail.MailAddress("*****@*****.**") //mail.DeliveryNotificationOptions = DeliveryNotificationOptions.None //Dim ysodAttachment As New System.Net.Mail.Attachment("filename", New System.Net.Mime.ContentType("")) //Dim ysodAttachment As New System.Net.Mail.Attachment("filename", "mediatype") //mail.Attachments.Add(ysodAttachment) InternalSendMail(mail); }
public bool SendMail(string To, string from, string subject, string body, bool isBodyHtml, System.Net.Mail.MailPriority priority, out string errorMessage) { throw new NotImplementedException(); }
public bool SendMail(string To, string from, string subject, string body, bool isBodyHtml, System.Net.Mail.MailPriority priority, out string errorMessage) { errorMessage = ""; Count++; return(true); }
public bool SendMail(string To, string ToCc, string ToBcc, string replyTo, string from, string displayName, string subject, string body, string attachFiles, bool IsBodyHtml, System.Net.Mail.MailPriority priority, out string errorMessage) { errorMessage = ""; Count++; return(true); }
/// <summary> /// Send a mail /// </summary> /// <param name="Senders">Senders for the mail</param> /// <param name="SendersCC">Senders cc for the mail</param> /// <param name="SendersBCC">Senders bcc for the mail</param> /// <param name="Subject">Subject for the mail</param> /// <param name="Body">Body of mail</param> /// <param name="ImagesAttached">List of images attached (only for HTML format)</param> /// <param name="FilesAttached">list of files attached to the mail</param> /// <param name="SSL">Is SSL required? </param> /// <param name="AuthenticationRequiered">The Authentication is required?</param> /// <param name="isHTML">The body of mail is HTML?</param> /// <param name="Result">Result of sending</param> /// <param name="mailPriority">Priority of mail</param> /// <returns>return true if the mail is submitted successfully</returns> public Boolean SendMail(List <String> Senders, List <String> SendersCC, List <String> SendersBCC, String Subject, String Body, List <ImageAttached> ImagesAttached, List <String> FilesAttached, Boolean SSL, Boolean AuthenticationRequiered, Boolean isHTML, out String Result, System.Net.Mail.MailPriority mailPriority = System.Net.Mail.MailPriority.Normal) { Boolean Res = false; String Sender = String.Empty; Result = String.Empty; System.Net.Mail.MailMessage mailmsg = PreparateMailMessage(Senders, SendersCC, SendersBCC, Subject, Body, ImagesAttached, isHTML, out Sender); if (FilesAttached != null) { FilesAttached.ForEach(fileattached => { if (System.IO.File.Exists(fileattached)) { mailmsg.Attachments.Add(new System.Net.Mail.Attachment(fileattached)); } }); } System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); smtp.Host = Server; if (AuthenticationRequiered) { smtp.Credentials = new System.Net.NetworkCredential(Mail, MailPassword); } smtp.Port = Port; smtp.EnableSsl = SSL; try { smtp.Send(mailmsg); Result = "Submitted successfully"; Res = true; } catch (Exception ex) { String sFilesAttached = String.Empty; if (FilesAttached != null) { FilesAttached.ForEach(fileattached => sFilesAttached += fileattached + ", "); } String Source = String.Empty; if (ex.Source != null) { Source = ex.Source; } Result = "Error:" + ex.Message + " object:" + Source + " Remitente:" + Sender + " Files" + sFilesAttached; } return(Res); }
/// <summary> /// Send emails in background /// </summary> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="listAttachments"></param> /// <param name="to"></param> /// <param name="cc"></param> /// <param name="bcc"></param> /// <param name="priority"></param> /// <returns></returns> public static bool SentEmail(string subject, string body, List <System.Net.Mail.Attachment> listAttachments = null, List <string> to = null, List <string> cc = null, List <string> bcc = null, System.Net.Mail.MailPriority priority = System.Net.Mail.MailPriority.Normal) { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.From = new System.Net.Mail.MailAddress(Properties.Settings.Default.SmtpEmail, Properties.Settings.Default.SmtpDisplayName); //Adding the emails addresses if (to != null) { foreach (var destinatario in to) { mail.To.Add(new System.Net.Mail.MailAddress(destinatario)); } } if (cc != null) { foreach (var destinatario in cc) { mail.CC.Add(new System.Net.Mail.MailAddress(destinatario)); } } if (bcc != null) { foreach (var destinatario in bcc) { mail.Bcc.Add(new System.Net.Mail.MailAddress(destinatario)); } } mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; mail.Priority = priority; System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(Properties.Settings.Default.SmtpServer, Properties.Settings.Default.SmtpPort); smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential(Properties.Settings.Default.SmtpEmail, Properties.Settings.Default.SmtpPassword); smtpClient.EnableSsl = Properties.Settings.Default.SmtpSSL; if (listAttachments != null) { foreach (var x in listAttachments) { mail.Attachments.Add(x); } } // Sent the message try { Console.WriteLine("Sending email..."); smtpClient.Send(mail); Console.WriteLine("Email sent successfully"); return(true); } catch (Exception ex) { Console.WriteLine("Sending error \n" + ex.StackTrace + " \n" + ex.InnerException.ToString()); return(false); } }
public RESTStatus SendMessage(SQLLib sql, WriteMessage message, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } if (message == null) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Name) == true) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Subject) == true) { return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(message.Text) == true) { return(RESTStatus.Fail); } ComputerData pc; lock (ni.sqllock) { pc = Computers.GetComputerDetail(sql, ni.Username); } string ErrorMessage; string Message; string Subject; Subject = "Support Request: " + message.Subject + " (" + pc.Computername + ")"; Message = "Support Request\n"; Message += "Computer: " + pc.Computername + " (" + pc.GroupingPath + ")\n"; Message += "Computer ID: " + pc.MachineID + "\n"; Message += "Date: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n"; Message += "Name: " + message.Name + "\n"; Message += "Subject: " + message.Subject + "\n"; Message += "IP Address: " + pc.IPAddress + "\n"; Message += "Version: " + pc.AgentVersion + " / " + pc.AgentVersionID.ToString() + "\n"; if (Settings.Default.UseContract == true) { Message += "Contract ID: " + pc.ContractID + "\n"; } Message += "\n"; Message += message.Text; System.Net.Mail.MailPriority prio = System.Net.Mail.MailPriority.Normal; switch (message.Priority) { case 0: prio = System.Net.Mail.MailPriority.Low; break; case 2: prio = System.Net.Mail.MailPriority.High; break; } if (MailSender.SendEMailAdmin(Subject, Message, prio, out ErrorMessage) == false) { FoxEventLog.WriteEventLog("Cannot send Support Request E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); return(RESTStatus.Fail); } return(RESTStatus.NoContent); }
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; } } }
public static void ErrorSendMail(string Content, string Email, string Subject = "New Message", System.Net.Mail.MailPriority Priority = System.Net.Mail.MailPriority.Normal, string FromName = "OBSSR Speaker Nomination System", string FromEmail = "*****@*****.**") { System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mail.scgcorp.com"); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.From = new System.Net.Mail.MailAddress(FromEmail, FromName, System.Text.Encoding.UTF8); if ((Email == "scg")) { mail.To.Add("*****@*****.**"); } else { mail.To.Add(new System.Net.Mail.MailAddress(Email)); mail.To.Add(FromEmail); } mail.Subject = Subject; mail.Priority = Priority; mail.IsBodyHtml = true; mail.Body = Content; try { smtp.Send(mail); } finally { mail.Dispose(); smtp = null; } }
public bool SendMail(string To, string ToCc, string ToBcc, string replyTo, string from, string displayName, string subject, string body, string attachFiles, bool IsBodyHtml, System.Net.Mail.MailPriority priority, out string errorMessage) { throw new NotImplementedException(); }
/// <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; } } }
internal bool SendMail(string strMailTo, string p, string p_3, string p_4, bool p_5, string strSubject, System.Net.Mail.MailPriority mailPriority, int p_8, bool p_9, string p_10, string p_11, ref string strError) { throw new NotImplementedException(); }