当前位置: 首页>>代码示例>>C#>>正文


C# Mail.MailMessage类代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: email

        public email()
        {
            Data rx=null;
            XmlSerializer reader = new XmlSerializer(typeof(Data));
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            using (FileStream input = File.OpenRead([email protected]"\data.xml"))
            {
                if(input.Length !=0)
                   rx = reader.Deserialize(input) as  Data;
            }

            if (rx != null)
            {
                try
                {
                    emaila = rx.userName;
                    passwd = UnprotectPassword(rx.passwd);
                    loginInfo = new NetworkCredential(emaila, passwd);
                    msg = new MailMessage();
                    smtpClient = new SmtpClient(rx.outGoing, rx.port);
                    smtpClient.EnableSsl = rx.ssl;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = loginInfo;
                    this.createMessage();
                    Environment.Exit(0);
                }
                catch (SmtpException sysex)
                {

                    MessageBox.Show("Taxi Notification App Has Encountered a Problem " +sysex.Message + " Please Check Your Configuration Settings", "Taxi Notification Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }
            else Environment.Exit(0);
        }
开发者ID:jozreel,项目名称:Projects,代码行数:34,代码来源:email.cs

示例8: Send

		private static void Send(){
			var mailMessage = new MailMessage{
			                                 	From = new MailAddress( "[email protected]", "65daigou.com" ),
			                                 	Subject = "You have new customer message from 65daigou.com",
			                                 	Body = "Good news from 65daigou.com",
			                                 	IsBodyHtml = true
			                                 };

			mailMessage.Headers.Add( "X-Priority", "3" );
			mailMessage.Headers.Add( "X-MSMail-Priority", "Normal" );
			mailMessage.Headers.Add( "ReturnReceipt", "1" );
			mailMessage.To.Add( "[email protected]" );
			mailMessage.To.Add( "[email protected]" );

			var smtpClient = new SmtpClient{
			                               	UseDefaultCredentials = false,
			                               	Credentials = new NetworkCredential( "eblaster", "MN3L45eS" ),
			                               	//Credentials = new NetworkCredential( "[email protected]", "111111aaaaaa" ),
			                               	Port = 587,
			                               	Host = "203.175.169.113",
			                               	EnableSsl = false
			                               };

			smtpClient.Send( mailMessage );
		}
开发者ID:kisflying,项目名称:kion,代码行数:25,代码来源:Program.cs

示例9: SendAsync

        public Task SendAsync(IdentityMessage message)
        {
            if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}" &&
                ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}" &&
                ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
            {
                System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();

                // To
                mailMsg.To.Add(new MailAddress(message.Destination, ""));

                // From
                mailMsg.From = new MailAddress("[email protected]", "DurandalAuth administrator");

                // Subject and multipart/alternative Body
                mailMsg.Subject = message.Subject;
                string html = message.Body;
                mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

                // Init SmtpClient and send
                SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"], Convert.ToInt32(587));
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPassword"]);
                smtpClient.Credentials = credentials;

                return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg, "token"));
            }
            else
            {
                return Task.FromResult(0);
            }
        }
开发者ID:Gionet,项目名称:DurandalAuth,代码行数:31,代码来源:EmailService.cs

示例10: 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

示例11: SendForm

        public ActionResult SendForm(EmailInfoModel emailInfo)
        {
            try
            {
                MailMessage msg = new MailMessage(CloudConfigurationManager.GetSetting("EmailAddr"), "[email protected]");
                var smtp = new SmtpClient("smtp.gmail.com", 587)
                {

                    Credentials = new NetworkCredential(CloudConfigurationManager.GetSetting("EmailAddr"), CloudConfigurationManager.GetSetting("EmailKey")),
                    EnableSsl = true
                };

                StringBuilder sb = new StringBuilder();
                msg.To.Add("[email protected]");
                msg.Subject = "Contact Us";
                msg.IsBodyHtml = false;

                sb.Append(Environment.NewLine);
                sb.Append("Email: " + emailInfo.Email);
                sb.Append(Environment.NewLine);
                sb.Append("Message: " + emailInfo.Message);

                msg.Body = sb.ToString();

                smtp.Send(msg);
                msg.Dispose();
                return RedirectToAction("Contact", "Home");
            }
            catch (Exception)
            {
                return View("Error");
            }
        }
开发者ID:JackTLi,项目名称:JTLPortalV2,代码行数:33,代码来源:HomeController.cs

示例12: SendEmail

        /// <summary>
        /// 结合配置文件改的
        /// </summary>
        /// <param name="mail"></param>
        public static bool SendEmail(string from, string displayName, string to0, string subject, string body, string encoding, MailPriority prioity)
        {
            if (string.IsNullOrEmpty(displayName))
                displayName = from;
            MailAddress _from = new MailAddress(from, displayName);

            MailAddress _to = new MailAddress(to0);
            MailMessage mail = new MailMessage(_from, _to);
            mail.Subject = subject;
            mail.Body = body;
            mail.BodyEncoding = System.Text.Encoding.Default;
            if (!string.IsNullOrEmpty(encoding))
            {
                mail.BodyEncoding = System.Text.Encoding.GetEncoding(encoding);
            }
            mail.IsBodyHtml = true;
            mail.Priority = prioity;

            Configs.Config cfg = new Configs.Config();
            // Override To
            if (!string.IsNullOrEmpty(cfg.Email.MailTo_Override))
            {
                var tos = cfg.Email.MailTo_Override.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                mail.To.Clear();
                foreach (var to in tos)
                {
                    mail.To.Add(to);
                }
            }
            return SendEmail(mail);
        }
开发者ID:popotans,项目名称:hjnlib,代码行数:35,代码来源:EmailUtil.cs

示例13: 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

示例14: 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

示例15: 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


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