• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Mail.SmtpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.Mail.SmtpClient的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient类的具体用法?C# SmtpClient怎么用?C# SmtpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SmtpClient类属于System.Net.Mail命名空间,在下文中一共展示了SmtpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SendEmail

        /// <summary>
        /// Send Gmail Email Using Specified Gmail Account
        /// </summary>
        /// <param name="address">Receipients Adresses</param>
        /// <param name="subject">Email Subject</param>
        /// <param name="message">Enail Body</param>
        /// <param name="AttachmentLocations">List of File locations, null if no Attachments</param>
        /// <param name="yourEmailAdress">Gmail Login Adress</param>
        /// <param name="yourPassword">Gmail Login Password</param>
        /// <param name="yourName">Display Name that Receipient Will See</param>
        /// <param name="IsBodyHTML">Is Message Body HTML</param>
        public static void SendEmail(List<string> addresses, string subject, string message, List<string> AttachmentLocations, string yourEmailAdress, string yourPassword, string yourName, bool IsBodyHTML)
        {
            try
            {
                string email = yourEmailAdress;
                string password = yourPassword;

                var loginInfo = new NetworkCredential(email, password);
                var msg = new MailMessage();
                var smtpClient = new SmtpClient("smtp.gmail.com", 587);


                msg.From = new MailAddress(email, yourName);
                foreach (string address in addresses)
                {
                    msg.To.Add(new MailAddress(address));
                }
                msg.Subject = subject;
                msg.Body = message;
                msg.IsBodyHtml = IsBodyHTML;
                if (AttachmentLocations != null)
                {
                    foreach (string attachment in AttachmentLocations)
                    {
                        msg.Attachments.Add(new Attachment(attachment));
                    }
                }
                smtpClient.EnableSsl = true;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = loginInfo;
                smtpClient.Send(msg);

            }
            catch { }
        }
开发者ID:sanyaade-fintechnology,项目名称:NinjaTrader,代码行数:46,代码来源:Gmail.cs


示例2: sendMessage

 private void sendMessage()
 {
     MailAddress adresa = new MailAddress("[email protected]");
     MailMessage zpráva;
     if (logFile)
     {
         string log;
         using (StreamReader reader = new StreamReader(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Info", "Log", "logStatusBaru.log")))
         {
             log = reader.ReadToEnd();
         }
         if (log.Length > 50000)
             log.Remove(50000);
         zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text + log);
     }
     else
     {
         zpráva = new MailMessage("[email protected]", "[email protected]", předmětTextBox.Text, textZprávyTextBox.Text);
     }
     SmtpClient klient = new SmtpClient();
     klient.Host = "smtp.gmail.com";
     klient.Port = 465;
     klient.EnableSsl = true;
     //klient.Send(zpráva);
 }
开发者ID:Cendrb,项目名称:UTU,代码行数:25,代码来源:OdeslatNázor.xaml.cs


示例3: Send

        /// <summary>
        /// Sends an email
        /// </summary>
        /// <param name="to">The list of recipients</param>
        /// <param name="subject">The subject of the email</param>
        /// <param name="body">The body of the email, which may contain HTML</param>
        /// <param name="htmlEmail">Should the email be flagged as "html"?</param>
        /// <param name="cc">A list of CC recipients</param>
        /// <param name="bcc">A list of BCC recipients</param>
        public static void Send(List<String> to, String subject, String body, bool htmlEmail = false, List<String> cc = null, List<String> bcc = null)
        {
            // Need to have at least one address
            if (to == null && cc == null && bcc == null)
                throw new System.ArgumentNullException("At least one of the address parameters (to, cc and bcc) must be non-null");

            NetworkCredential credentials = new NetworkCredential(JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.AdminEmail), JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPPassword));
            // Set up the built-in MailMessage
            MailMessage mm = new MailMessage();
            mm.From = new MailAddress(credentials.UserName, "Just Press Play");
            if (to != null) foreach (String addr in to) mm.To.Add(new MailAddress(addr, "Test"));
            if (cc != null) foreach (String addr in cc) mm.CC.Add(new MailAddress(addr));
            if (bcc != null) foreach (String addr in bcc) mm.Bcc.Add(new MailAddress(addr));
            mm.Subject = subject;
            mm.IsBodyHtml = htmlEmail;
            mm.Body = body;
            mm.Priority = MailPriority.Normal;

            // Set up the server communication
            SmtpClient client = new SmtpClient
                {
                    Host = JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPServer),
                    Port = int.Parse(JPPConstants.SiteSettings.GetValue(JPPConstants.SiteSettings.SMTPPort)),
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = credentials
                };

            client.Send(mm);
        }
开发者ID:RIT-MAGIC,项目名称:JustPressPlay,代码行数:40,代码来源:Email.cs


示例4: SendMessage

        public static void SendMessage(SmtpServer server, string from, string to, string subject, string content)
        {
            // compress Foe message and convert the compressed data to Base64 string
            byte[] compressedData = Foe.Common.CompressionManager.Compress(Encoding.UTF8.GetBytes(content));
            string based64 = Convert.ToBase64String(compressedData);

            // send email
            try
            {
                // create mail
                MailMessage mail = new MailMessage(from, to, subject, based64);

                // connect and send
                SmtpClient smtp = new SmtpClient(server.ServerName, server.Port);
                if (server.AuthRequired)
                {
                    smtp.EnableSsl = server.SslEnabled;
                    smtp.UseDefaultCredentials = false;
                    NetworkCredential cred = new NetworkCredential(server.UserName, server.Password);
                    smtp.Credentials = cred;
                }
                smtp.Send(mail);
            }
            catch (Exception except)
            {
                throw except;
            }
        }
开发者ID:gcode-mirror,项目名称:foe-project,代码行数:28,代码来源:MessageManager.cs


示例5: Send_with_Auth_Success_Test

        public void Send_with_Auth_Success_Test()
        {
            using (var server = new SmtpServerForUnitTest(
                address: IPAddress.Loopback,
                port: 2525,
                credentials: new[] { new NetworkCredential("[email protected]", "[email protected]$$w0rd") }))
            {
                server.Start();

                var client = new SmtpClient("localhost", 2525);
                client.Credentials = new NetworkCredential("[email protected]", "[email protected]$$w0rd");
                client.Send(
                    "[email protected]",
                    "[email protected],[email protected]",
                    "[HELLO WORLD]",
                    "Hello, World.");

                server.ReceivedMessages.Count().Is(1);
                var msg = server.ReceivedMessages.Single();
                msg.MailFrom.Is("<[email protected]>");
                msg.RcptTo.OrderBy(_ => _).Is("<[email protected]>", "<[email protected]>");
                msg.From.Address.Is("[email protected]");
                msg.To.Select(_ => _.Address).OrderBy(_ => _).Is("[email protected]", "[email protected]");
                msg.CC.Count().Is(0);
                msg.Subject.Is("[HELLO WORLD]");
                msg.Body.Is("Hello, World.");
            }
        }
开发者ID:jsakamoto,项目名称:smtp-server-4unittest,代码行数:28,代码来源:SmtpServerForUnitTestTest.cs


示例6: SendMail

 /// <summary>
 /// Sends an email
 /// </summary>
 /// <param name="Message">The body of the message</param>
 public void SendMail(string Message)
 {
     try
     {
         System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
         char[] Splitter = { ',' };
         string[] AddressCollection = to.Split(Splitter);
         for (int x = 0; x < AddressCollection.Length; ++x)
         {
             message.To.Add(AddressCollection[x]);
         }
         message.Subject = subject;
         message.From = new System.Net.Mail.MailAddress((from));
         message.Body = Message;
         message.Priority = Priority_;
         message.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.IsBodyHtml = true;
         if (Attachment_ != null)
         {
             message.Attachments.Add(Attachment_);
         }
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(Server,Port);
         if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
         {
             smtp.Credentials = new System.Net.NetworkCredential(UserName,Password);
         }
         smtp.Send(message);
         message.Dispose();
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString());
     }
 }
开发者ID:summer-breeze,项目名称:ChengGouHui,代码行数:39,代码来源:EmailSender.cs


示例7: Enviar

        protected void Enviar(object sender, EventArgs e)
        {
            MailMessage email = new MailMessage();
            MailAddress de = new MailAddress(txtEmail.Text);

            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");
            email.To.Add("[email protected]");

            email.From = de;
            email.Priority = MailPriority.Normal;
            email.IsBodyHtml = false;
            email.Subject = "Sua Jogada: " + txtAssunto.Text;
            email.Body = "Endereço IP: " + Request.UserHostAddress + "\n\nNome: " + txtNome.Text + "\nEmail: " + txtEmail.Text + "\nMensagem: " + txtMsg.Text;

            SmtpClient enviar = new SmtpClient();

            enviar.Host = "smtp.live.com";
            enviar.Credentials = new NetworkCredential("[email protected]", "");
            enviar.EnableSsl = true;
            enviar.Send(email);
            email.Dispose();

            Limpar();

            ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('Email enviado com sucesso!');", true);
        }
开发者ID:JulianRSena,项目名称:projeto-suajogada,代码行数:30,代码来源:Contato.aspx.cs


示例8: SendMail

        public string SendMail(string from, string passsword, string to, string bcc, string cc, string subject, string body, string UserName = "", string Password = "")
        {
            string response = "";
            try
            {
                using (SmtpClient smtp = new SmtpClient())
                {
                    MailMessage mail = new MailMessage();
                    mail.To.Add(to);
                    mail.From = new MailAddress(UserName);
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.IsBodyHtml = true;
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = false;
                    smtp.EnableSsl = true;
                    smtp.Host = "smtp.zoho.com";
                    smtp.Port = 587;
                    smtp.Credentials = new NetworkCredential(UserName, Password);
                    smtp.Send(mail);
                    response = "Success";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }

            return response;
        }
开发者ID:socioboard,项目名称:socioboard-core,代码行数:31,代码来源:MailSenderZoho.cs


示例9: sendEmail

        public static void sendEmail(string emailFrom, string password, string emailTo, string subject, string body)
        {
            string smtpAddress = "smtp.gmail.com";
            int portNumber = 587;
            bool enableSSL = true;

            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom); //email của mình
                mail.To.Add(emailTo); //gửi tới ai
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;

                // Can set to false, if you are sending pure text.

                //mail.Attachments.Add(new Attachment("H:\\cpaior2012_path.pdf"));

                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    smtp.Send(mail);
                }
            }
        }
开发者ID:anhphamkstn,项目名称:DVMC,代码行数:26,代码来源:Mail.cs


示例10: SendEmail

        public static void SendEmail(string email, string subject, string body)
        {
            string fromAddress = ConfigurationManager.AppSettings["FromAddress"];
            string fromPwd = ConfigurationManager.AppSettings["FromPassword"];
            string fromDisplayName = ConfigurationManager.AppSettings["FromDisplayNameA"];
            //string cc = ConfigurationManager.AppSettings["CC"];
            //string bcc = ConfigurationManager.AppSettings["BCC"];

            MailMessage oEmail = new MailMessage
            {
                From = new MailAddress(fromAddress, fromDisplayName),
                Subject = subject,
                IsBodyHtml = true,
                Body = body,
                Priority = MailPriority.High
            };
            oEmail.To.Add(email);
            string smtpServer = ConfigurationManager.AppSettings["SMTPServer"];
            string smtpPort = ConfigurationManager.AppSettings["SMTPPort"];
            string enableSsl = ConfigurationManager.AppSettings["EnableSSL"];
            SmtpClient client = new SmtpClient(smtpServer, Convert.ToInt32(smtpPort))
            {
                EnableSsl = enableSsl == "1",
                Credentials = new NetworkCredential(fromAddress, fromPwd)
            };

            client.Send(oEmail);
        }
开发者ID:innoist,项目名称:Inventory-POS-IST,代码行数:28,代码来源:Utility.cs


示例11: SendMail

 /// <summary>
 /// Envia un correo por medio de un servidor SMTP
 /// </summary>
 /// <param name="from">correo remitente</param>
 /// <param name="fromPwd">contraseña del correo del remitente</param>
 /// <param name="userTo">usuario que solicito la recuperación de la contraseña</param>
 /// <param name="subject">encabezado del correo</param>
 /// <param name="smtpClient">sercidor smtp</param>
 /// <param name="port">puerto del servidor smtp</param>
 /// <returns>respuesta del envio</returns>
 public string SendMail(string from, string fromPwd, string userTo, string subject, string smtpClient, int port)
 {
     currentUser = userTo;
     userTo = GetCorreoUsuario(currentUser);
     if (userTo.Equals(string.Empty))
         return "El usuario no esta registrado.";
     else if (!InsertPassword(currentUser))
         return "No se ha podido crear una nueva contraseña. Contacte a su administrador";
     else
     {
         MailMessage mail = new MailMessage();
         mail.From = new MailAddress(from);
         mail.To.Add(userTo);
         mail.Subject = subject;
         mail.IsBodyHtml = true;
         mail.Body = GetMsg(from, currentUser);
         SmtpClient smtp = new SmtpClient(smtpClient);
         smtp.Credentials = new System.Net.NetworkCredential(from, fromPwd);
         smtp.Port = port;
         try
         {
             smtp.Send(mail);
             return "Se ha enviado su nueva contraseña. Revise su correo y vuelva a intentarlo";
         }
         catch (Exception ex)
         {
             return "No se ha podido completar la solicitud: " + ex.Message;
         }
     }   
 }
开发者ID:jibarradelgado,项目名称:medicuri,代码行数:40,代码来源:BlRecuperarContraseña.cs


示例12: SendEmailThroughGmail

        /// <summary>
        /// 使用Gmail发送邮件
        /// </summary>
        /// <param name="gmailAccount">Gmail账号</param>
        /// <param name="gmailPassword">Gmail密码</param>
        /// <param name="to">接收人邮件地址</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="attachPath">附件</param>
        /// <returns>是否发送成功</returns>
        public static bool SendEmailThroughGmail(String gmailAccount, String gmailPassword, String to, String subject, String body,
            String attachPath)
        {
            try
            {
                SmtpClient client = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(gmailAccount, gmailPassword),
                    Timeout = 20000
                };

                using (MailMessage mail = new MailMessage(gmailAccount, to) { Subject = subject, Body = body })
                {
                    mail.IsBodyHtml = true;

                    if (!string.IsNullOrEmpty(attachPath))
                    {
                        mail.Attachments.Add(new Attachment(attachPath));
                    }

                    client.Send(mail);
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
开发者ID:dalinhuang,项目名称:jxt-zhichengxinda,代码行数:45,代码来源:EmailUtility.cs


示例13: send_email_alert

        public void send_email_alert(string alert_message)
        {


          
            var fromAddress = new MailAddress("[email protected]", "Selenium Alert");
            var toAddress = new MailAddress("[email protected]", "Max");
            const string fromPassword = "098AZQ102030";
            const string subject = "Selenium Alert";
            

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = alert_message
            })
            {
                smtp.Send(message);
            }
        }
开发者ID:maxunger,项目名称:driv_t,代码行数:29,代码来源:EmailAlert.cs


示例14: Application_Error

        void Application_Error(object sender, EventArgs e)
        {
            var exception = Server.GetLastError();
            var httpException = exception as HttpException;
            if (httpException != null)
            {
                //switch (httpException.GetHttpCode())
                //{
                //    case 404:
                //        HttpContext.Current.Session["Message"] = "Страница не найдена!";
                //        break;
                //    case 500:
                //        //action = "Error";
                //        break;
                //    default:
                //        // action = "Error";
                //        HttpContext.Current.Session["Message"] = "Неизвестная ошибка. Попробуйте повторить действие позже.";
                //        break;
                //}
            }
            else
                HttpContext.Current.Session["Message"] = exception.Message;

            var message = new MailMessage();
            message.To.Add(new MailAddress("[email protected]"));
            message.Subject = "psub.net error";
            message.Body = exception.Message;
            message.IsBodyHtml = true;
            var client = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network };
            client.Send(message);

            Response.Redirect(@"~/Exception/Error");
        }
开发者ID:pashaiva,项目名称:psub.Web,代码行数:33,代码来源:Global.asax.cs


示例15: SendContactEmail

        // email from contact form
        public void SendContactEmail(Registrant registrant)
        {
            emailBody += "NAME: " + registrant.FirstName + " " + registrant.LastName;
            emailBody += "<br><br>";
            emailBody += "EMAIL: " + registrant.Email;
            emailBody += "<br><br>";
            emailBody += "ZIP: " + registrant.ZipCode;
            emailBody += "<br><br>";
            emailBody += "COMMENTS:";
            emailBody += "<br><br>";
            emailBody += registrant.Comments;

            var message = new MailMessage(SMTPAddress, contactAddress)
            {
                Subject = "Contact Inquiry from Website",
                IsBodyHtml = true,
                Body = emailBody
            };

            var mailer = new SmtpClient();
            mailer.Host = SMTPHost;
            mailer.Credentials = new System.Net.NetworkCredential(SMTPAddress, SMTPPassword);
            mailer.Send(message);

            return;
        }
开发者ID:soularise,项目名称:NEST-MASTER,代码行数:27,代码来源:MailHandler.cs


示例16: Send

        public Boolean Send(String toEmail, String toFriendlyName, String subject, String HTML)
        {
            try
            {
                SmtpClient smtpclient = new SmtpClient();
                smtpclient.Host = this.smtpserver;
                smtpclient.Credentials = new System.Net.NetworkCredential(this.smtpusername, this.smtppassword);
                smtpclient.Port = this.smtpport;
                smtpclient.EnableSsl = this.smtpssl;

                MailMessage message = new MailMessage();
                message.To.Add(new MailAddress(toEmail, toFriendlyName));
                message.From = new MailAddress(this.emailfromaddress, this.emailfromfriendly);
                message.ReplyToList.Add(new MailAddress(this.emailreplyaddress, this.emailfromfriendly));
                message.Subject = subject;
                message.SubjectEncoding = Encoding.UTF8;
                message.IsBodyHtml = true;
                message.Body = HTML;
                message.BodyEncoding = Encoding.UTF8;

                smtpclient.Send(message);

                return true;
            }
            catch (Exception ex)
            {
                this.errormessage = ex.Message;
                return false;
            }
        }
开发者ID:Trexis,项目名称:financemanager,代码行数:30,代码来源:email.cs


示例17: Send

        public static void Send(Mail mail)
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(mail.From, "Money Pacific Service");
            msg.To.Add(new MailAddress(mail.To));
            msg.Subject = mail.Subject;
            msg.Body = mail.Body;

            msg.IsBodyHtml = true;
            msg.BodyEncoding = new System.Text.UTF8Encoding();
            msg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            System.Net.NetworkCredential user = new
                System.Net.NetworkCredential(
                    ConfigurationManager.AppSettings["sender"],
                    ConfigurationManager.AppSettings["senderPass"]
                    );

            smtp.EnableSsl = true;
            smtp.Credentials = user;
            smtp.Port = 587; //or use 465 
            object userState = msg;

            try
            {
                //you can also call client.Send(msg)
                smtp.SendAsync(msg, userState);
            }
            catch (SmtpException)
            {
                //Catch errors...
            }
        }
开发者ID:vramsngrai1994,项目名称:mkpacific-ltd,代码行数:35,代码来源:MPMail.cs


示例18: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            int sayi;

            try
            {
                Email = Request.QueryString["Email"];
            }
            catch (Exception)
            {
            }

            DataRow drSayi = klas.GetDataRow("Select * from Kullanici Where Email='" + Email + "'   ");
            sayi = Convert.ToInt32(drSayi["Sayi"].ToString());

            MailMessage msg = new MailMessage();//yeni bir mail nesnesi Oluşturuldu.
            msg.IsBodyHtml = true; //mail içeriğinde html etiketleri kullanılsın mı?

            msg.To.Add(Email);//Kime mail gönderilecek.
            msg.From = new MailAddress("[email protected]", "akorkupu.com", System.Text.Encoding.UTF8);//mail kimden geliyor, hangi ifade görünsün?
            msg.Subject = "Üyelik Onay Maili";//mailin konusu
            msg.Body = "<a href='http://www.akorkupu.com/UyeOnay.aspx?x=" + sayi + "&Email=" + Email + "'>Üyelik Onayı İçin Tıklayın</a>";//mailin içeriği

            SmtpClient smp = new SmtpClient();
            smp.Credentials = new NetworkCredential("[email protected]", "1526**rG");//kullanıcı adı şifre
            smp.Port = 587;
            smp.Host = "smtp.gmail.com";//gmail üzerinden gönderiliyor.
            smp.EnableSsl = true;
            smp.Send(msg);//msg isimli mail gönderiliyor.

        }
开发者ID:ramazanguclu,项目名称:AkorKupu.com,代码行数:31,代码来源:UyeTamam.aspx.cs


示例19: SendAsync

        private void SendAsync(string toStr, string fromStr, string subject, string message)
        {
            try
            {
                var from = new MailAddress(fromStr);
                var to = new MailAddress(toStr);

                var em = new MailMessage(from, to) { BodyEncoding = Encoding.UTF8, Subject = subject, Body = message };
                em.ReplyToList.Add(from);

                var client = new SmtpClient(SmtpServer) { Port = Port, EnableSsl = SslEnabled };

                if (UserName != null && Password != null)
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials = new NetworkCredential(UserName, Password);
                }

                client.Send(em);
            }
            catch (Exception e)
            {
                Log.Error("Could not send email.", e);
                //Swallow as this was on an async thread.
            }
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:26,代码来源:SystemMailProvider.cs


示例20: Button1_Click

 protected void Button1_Click(object sender, EventArgs e)
 {            
     DataView DV1 = (DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
     foreach (DataRowView DRV1 in DV1)
     {
         string ToAddress = DRV1["Email_Address"].ToString();
         MailMessage message = new MailMessage("[email protected]", ToAddress);                
         message.Body = TextBox2.Text;
         message.Subject = TextBox1.Text;
         message.BodyEncoding = System.Text.Encoding.UTF8;
         string Path = HttpContext.Current.Server.MapPath("~/images/EnewsLetters/Temp/");
         FileUpload1.SaveAs(Path + FileUpload1.FileName);
         Attachment attach1 = new Attachment(Path + FileUpload1.FileName);
         message.Attachments.Add(attach1);
         SmtpClient mailserver = new SmtpClient("amcsmail02.amcs.com", 25);
         try
         {
             mailserver.Send(message);
         }
         catch
         {
         }
         attach1.Dispose();
     }
     System.IO.File.Delete(HttpContext.Current.Server.MapPath("~/images/EnewsLetters/Temp/") + FileUpload1.FileName);
     TextBox1.Text = "";
     TextBox2.Text = "";
 }
开发者ID:tstanley93,项目名称:ARC.ORG-trunk,代码行数:28,代码来源:eNewsLetter_Email.aspx.cs



注:本文中的System.Net.Mail.SmtpClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mail.SmtpConnection类代码示例发布时间:2022-05-26
下一篇:
C# Mail.MailMessage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap