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


C# MailMessage类代码示例

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


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

示例1: TestEmail

    string TestEmail(Settings settings)
    {
        string email = settings.Email;
        string smtpServer = settings.SmtpServer;
        string smtpServerPort = settings.SmtpServerPort.ToString();
        string smtpUserName = settings.SmtpUserName;
        string smtpPassword = settings.SmtpPassword;
        string enableSsl = settings.EnableSsl.ToString();

        var mail = new MailMessage
        {
            From = new MailAddress(email, smtpUserName),
            Subject = string.Format("Test mail from {0}", smtpUserName),
            IsBodyHtml = true
        };
        mail.To.Add(mail.From);
        var body = new StringBuilder();
        body.Append("<div style=\"font: 11px verdana, arial\">");
        body.Append("Success");
        if (HttpContext.Current != null)
        {
            body.Append(
                "<br /><br />_______________________________________________________________________________<br /><br />");
            body.AppendFormat("<strong>IP address:</strong> {0}<br />", Utils.GetClientIP());
            body.AppendFormat("<strong>User-agent:</strong> {0}", HttpContext.Current.Request.UserAgent);
        }

        body.Append("</div>");
        mail.Body = body.ToString();

        return Utils.SendMailMessage(mail, smtpServer, smtpServerPort, smtpUserName, smtpPassword, enableSsl.ToString());
    }
开发者ID:aelagawy,项目名称:BlogEngine.NET,代码行数:32,代码来源:SettingsController.cs

示例2: SendEmail

    private void SendEmail()
    {
        String content = string.Empty;

        var objEmail = new MailMessage();
        objEmail.From = new MailAddress("[email protected]", "Sender");

        objEmail.Subject = "Test send email on GoDaddy account";
        objEmail.IsBodyHtml = true;

        var smtp = new SmtpClient();
        smtp.Host = "smtpout.secureserver.net";
        smtp.Port = 80;
        smtp.EnableSsl = false;
        // and then send the mail
        //        ServicePointManager.ServerCertificateValidationCallback =
        //delegate(object s, X509Certificate certificate,
        //X509Chain chain, SslPolicyErrors sslPolicyErrors)
        //{ return true; };

        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        //smtp.UseDefaultCredentials = false;
        smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "#passw0rd#");

        objEmail.To.Add("[email protected]");
         objEmail.To.Add("[email protected]");
        objEmail.Body = content;

        smtp.Send(objEmail);
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:30,代码来源:Test_SendEmail.aspx.cs

示例3: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (Request.Form.Count > 0)
            {
                try
                {
                    SmtpClient client = new SmtpClient();
                    var mail = new MailMessage(ConfigurationManager.AppSettings["FormEmailFrom"], ConfigurationManager.AppSettings["FormEmailTo"]);
                    mail.Subject = "New OSI Contact Form Submission";
                    mail.Body = "Name: " + Request.Form["name"] + "\n" +
                                          "Email: " + Request.Form["email"] + "\n" +
                                          "Message: " + Request.Form["message"];

                    client.Send(mail);

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "onContact()", true);
                }
                catch (Exception)
                {

                }
            }
        }
    }
开发者ID:pmstrategygroup,项目名称:osi,代码行数:26,代码来源:news.aspx.cs

示例4: SendMail

    /// <summary>
    /// 外发邮件支持群发
    /// </summary>
    /// <param name="MessageFrom">发件人</param>
    /// <param name="MessageTo">群发多用户使用"|"格开地址</param>
    /// <param name="MessageSubject">邮件主题</param>
    /// <param name="MessageBody">邮件内容</param>
    /// <returns>是否发送成功</returns>
    public bool SendMail(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody)
    {
        MailMessage message = new MailMessage();

        message.From = MessageFrom;

        string[] mtuser = MessageTo.Split('|');
        foreach (string m in mtuser)
        {
            message.To.Add(m);
        }

        message.Subject = MessageSubject;
        message.Body = MessageBody;
        message.IsBodyHtml = true;              //是否为html格式
        message.Priority = MailPriority.High;   //发送邮件的优先等级

        SmtpClient sc = new SmtpClient("smtp.gmail.com"); //指定发送邮件的服务器地址或IP

        sc.Port = 587;   //指定发送邮件端口
        sc.EnableSsl = true;
        sc.Credentials = new System.Net.NetworkCredential("[email protected]", "000000"); //指定登录服务器的用户名和密码
        //try
        //{
            sc.Send(message);       //发送邮件
        //}
        //catch
        //{
        //    return false;
        //}
        return true;
    }
开发者ID:Angliy,项目名称:DemoForTest,代码行数:40,代码来源:Default3.aspx.cs

示例5: sendMail

    public bool sendMail(EmailModel emailModel)
    {
        MailMessage mail = new MailMessage();
        SmtpClient client = new SmtpClient();
        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Host = "smtp.gmail.com";
        mail.To.Add(new MailAddress("[email protected]"));
        mail.From = new MailAddress("[email protected]");
        client.Credentials = new System.Net.NetworkCredential("[email protected]", "haythamfaraz");
        mail.Subject = emailModel.name + " | " + emailModel.service;
        client.EnableSsl = true;
        mail.IsBodyHtml = true;
        mail.Body = "<html>"
+ "<body>"
+ "<div> <h2>Email: " + emailModel.email + " </h2> </br>"
+ "<h2> Name: " + emailModel.name + "</h2> </br>" +
"<h2> Phone number: " + emailModel.phoneNumber + "</h2> </br>" +
"<h2> Service: " + emailModel.service + "</h2> </br>" +
"<h2> More Information: " + emailModel.message + "</h2> </br>"
+ "</div>"
+ "</body>"
+ "</html>";
        try
        {
            client.Send(mail);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
开发者ID:globaltechservices,项目名称:globaltechservices.github.io,代码行数:34,代码来源:SupportModel.cs

示例6: Mail_Gonder

    private void Mail_Gonder(string gonderen, string gonderen_sifre, string alan, string baslik, string icerik)
    {
        string smtpAddress = "smtp.gmail.com";
        int portNumber = 587;
        bool enableSSL = true;

        string emailFrom = gonderen;
        string password = gonderen_sifre;
        string emailTo = alan;
        string subject = baslik;
        string body = icerik;

        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(emailFrom);
            mail.To.Add(emailTo);
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = true;
            // Can set to false, if you are sending pure text.

            using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
            {
                smtp.Credentials = new NetworkCredential(emailFrom, password);
                smtp.EnableSsl = enableSSL;
                smtp.Send(mail);
            }

        }
    }
开发者ID:ramazancesur,项目名称:RentACar,代码行数:30,代码来源:Sifre-Unuttum.aspx.cs

示例7: Send

 public void Send()
 {
     Result = "";
     Success = true;
     try
     {
         // send email
         var senderAddress = new MailAddress(SenderAddress, SenderName);
         var toAddress = new MailAddress(Address);
         var smtp = new SmtpClient
         {
             Host = SmtpServer,
             Port = SmtpPort,
             EnableSsl = true,
             DeliveryMethod = SmtpDeliveryMethod.Network,
             UseDefaultCredentials = false,
             Credentials = new NetworkCredential(senderAddress.Address, Password),
             Timeout = 5000
         };
         smtp.ServicePoint.MaxIdleTime = 2;
         smtp.ServicePoint.ConnectionLimit = 1;
         using (var mail = new MailMessage(senderAddress, toAddress))
         {
             mail.Subject = Subject;
             mail.Body = Body;
             mail.IsBodyHtml = true;
             smtp.Send(mail);
         }
     }
     catch(Exception ex)
     {
         Result = ex.Message + " " + ex.InnerException;
         Success = false;
     }
 }
开发者ID:jaroban,项目名称:Web,代码行数:35,代码来源:Email.cs

示例8: Submit_Click

    public void Submit_Click(object sender, EventArgs e)
    {
        try
        {
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

            smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "NenDdjlbnczNtrcn5483undSend3n");
            smtpClient.UseDefaultCredentials = false;
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtpClient.EnableSsl = true;
            MailMessage mail = new MailMessage();

            //Setting From , To and CC
            mail.From = new MailAddress(txtemail.Text);
            mail.To.Add(new MailAddress("[email protected]"));
            mail.CC.Add(new MailAddress("[email protected]"));
            mail.Subject = txtsubject.Text+" "+txtcmpnm.Text+" "+txtName.Text;
            mail.Body = txtmsg.Text;

            smtpClient.Send(mail);
        }
        catch (Exception ee)
        {
        }
    }
开发者ID:EreminDm,项目名称:FriendsPartnersheep,代码行数:25,代码来源:contactus.aspx.cs

示例9: SendEmail

        /// <summary>
        /// 发送Email功能函数
        /// </summary>
        /// <param name="to">接收人</param>
        /// <param name="subject">主题</param>
        /// <param name="body">内容</param>
        /// <param name="isBodyHtml">是否是HTML格式Mail</param>
        /// <returns>是否成功</returns> 
        public static void SendEmail(string to, string subject, string body, bool isBodyHtml)
        {
            //设置smtp
            var smtp = new SmtpClient
                           {
                               Host = ConfigurationManager.AppSettings["SMTPServer"],
                               EnableSsl = bool.Parse(ConfigurationManager.AppSettings["SMTPServerEnableSsl"]),
                               Port = int.Parse(ConfigurationManager.AppSettings["SMTPServerPort"]),
                               Credentials =
                                   new NetworkCredential(ConfigurationManager.AppSettings["SMTPServerUser"],
                                                         ConfigurationManager.AppSettings["SMTPServerPassword"])
                           };

            ////开一个Message
            var mail = new MailMessage
                           {
                               Subject = subject,
                               SubjectEncoding = Encoding.GetEncoding("utf-8"),
                               BodyEncoding = Encoding.GetEncoding("utf-8"),
                               From =
                                   new MailAddress(ConfigurationManager.AppSettings["SMTPServerUser"],
                                                   ConfigurationManager.AppSettings["SMTPServerUserDisplayName"]),
                               IsBodyHtml = isBodyHtml,
                               Body = body
                           };

            mail.To.Add(to);

            var ised = new InternalSendEmailDelegate(smtp.Send);
            ised.BeginInvoke(mail, null, null);
            //smtp.SendAsync(mail, null);
        }
开发者ID:peisheng,项目名称:datacenter,代码行数:40,代码来源:Email.cs

示例10: Run

        public static void Run()
        {
            // ExStart:SendingBulkEmails
            // Create SmtpClient as client and specify server, port, user name and password
            SmtpClient client = new SmtpClient("mail.server.com", 25, "Username", "Password");

            // Create instances of MailMessage class and Specify To, From, Subject and Message
            MailMessage message1 = new MailMessage("[email protected]", "[email protected]", "Subject1", "message1, how are you?");
            MailMessage message2 = new MailMessage("[email protected]", "[email protected]", "Subject2", "message2, how are you?");
            MailMessage message3 = new MailMessage("[email protected]", "[email protected]", "Subject3", "message3, how are you?");

            // Create an instance of MailMessageCollection class
            MailMessageCollection manyMsg = new MailMessageCollection();
            manyMsg.Add(message1);
            manyMsg.Add(message2);
            manyMsg.Add(message3);

            // Use client.BulkSend function to complete the bulk send task
            try
            {
                // Send Message using BulkSend method
                client.Send(manyMsg);                
                Console.WriteLine("Message sent");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            // ExEnd:SendingBulkEmails
        }
开发者ID:aspose-email,项目名称:Aspose.Email-for-.NET,代码行数:30,代码来源:SendingBulkEmails.cs

示例11: btnSend_Click

    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName = Server.MapPath("~/APP_Data/ContactForm.txt");
            string mailBody = File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Name##", txbxName.Text);
            mailBody = mailBody.Replace("##Email##", txbxMail.Text);
            mailBody = mailBody.Replace("##Phone##", txbxPhone.Text);
            mailBody = mailBody.Replace("##Comments##", txbxComents.Text);

            MailMessage myMessage = new MailMessage();
            myMessage.Subject = "Comentario en el Web Site";
            myMessage.Body = mailBody;
            myMessage.From = new MailAddress("[email protected]", "Uge Pruebas");
            myMessage.To.Add(new MailAddress("[email protected]", "Eugenio"));
            myMessage.ReplyToList.Add(new MailAddress(txbxMail.Text));
            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.Send(myMessage);

            laMessageSent.Visible=true;
            MessageSentPara.Visible = true;
            FormTable.Visible = false;
        }
    }
开发者ID:ugeHidalgo,项目名称:theClub,代码行数:26,代码来源:ContactForm.ascx.cs

示例12: btnRecoverPassword_Click

    protected void btnRecoverPassword_Click(object sender, EventArgs e)
    {
        try
        {
            con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString());
            con.Open();

            string query = string.Format("SELECT * FROM users WHERE email='{0}'", txtEmail.Text);
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            DataTable dt = new DataTable();
            da.Fill(dt);

            if (dt.Rows.Count != 0)
            {
                if (lblError.Text != null)
                    lblError.Text = "";
                //Create Mail Message object and construct mail
                MailMessage recoverPassword = new MailMessage();
                recoverPassword.To = dt.Rows[0]["email"].ToString();
                recoverPassword.From = "[email protected]  ";
                recoverPassword.Subject = "Your password";
                recoverPassword.Body = "Your CricVision user password is " + dt.Rows[0]["password"].ToString();
                //SmtpMail.Send(recoverPassword);
                lblError.Text = "Your password has been sent to your Email";
            }
            else
                lblError.Text = "Email address not found. Try again!";
        }
        catch (Exception ex)
        {
            lblError.Text = "A database error has occurred";
        }
    }
开发者ID:GauravButola,项目名称:Online-sports-portal,代码行数:33,代码来源:PasswordRecovery.aspx.cs

示例13: btnPasswordRecover_Click

    protected void btnPasswordRecover_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            Customer cust = context.Customers.Where(i => i.email==txtEmail.Text).FirstOrDefault();
            if (cust == null)
            {
                string title = "User ID not found";
                string message = "No user found with the given email ID. Please provide the email ID you signed up with.";
                string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
            }
            else
            {
                string email = cust.email;
                string password = cust.Password;
                MailMessage mail = new MailMessage("[email protected]", email);
                mail.Subject = "Password for your eCommerce ID";
                mail.Body = "Your password for eCommerce is : " + password;
                mail.IsBodyHtml = false;

                SmtpClient smp = new SmtpClient();
                //smp.Send(mail);

                string title = "Password sent!";
                string message = "Your password has been sent to " + email;
                string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
            }
        }
    }
开发者ID:GauravButola,项目名称:eCommerce,代码行数:31,代码来源:forgotPassword.aspx.cs

示例14: Send

 public static bool Send(PESMail mail)
 {
     SmtpClient smtp = new SmtpClient();
     smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings.Get("Sender"), ConfigurationManager.AppSettings.Get("MailPass"));
     smtp.Host = ConfigurationManager.AppSettings.Get("SmtpHost");
     smtp.Port = Commons.ConvertToInt(ConfigurationManager.AppSettings.Get("SmtpPort"),25);
     smtp.EnableSsl = true;
     using (MailMessage message = new MailMessage())
     {
         message.From = new MailAddress(ConfigurationManager.AppSettings.Get("defaultSender"));
         for (int i = 0; i < mail.List.Count;i++ )
         {
             message.To.Add(mail.List[i].ToString());
         }
         message.Subject = mail.Subject;
         message.Body = mail.Content;
         message.IsBodyHtml = mail.IsHtml;
         try
         {
             smtp.Send(message);
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
开发者ID:lengocluyen,项目名称:pescode,代码行数:28,代码来源:PESMails.cs

示例15: SendMail

    public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
    {
        try
        {
            NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);

            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
开发者ID:lordiejake,项目名称:aspDesignTemlpates,代码行数:25,代码来源:MailSender.cs


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