0

所有客户端 onClick 属性和文本框 ID 正是源代码中已在此处指出的那些,但是一旦我运行页面并插入我的电子邮件地址,如果不会引发任何错误或异常。它什么也不做。你们知道我在这里做错了什么吗?不要介意电子邮件和 smtp 服务器地址。为了安全起见,我更改了这些。

谢谢!亲切的问候。涡流

public partial class _Default : System.Web.UI.Page
{
    protected void btnEmail_Click(object sender, EventArgs e)
    {
        emailArcTech();
        emailUser();
    }

    private void emailUser()
    {
        try
        {
            //initialize email object
            MailMessage mail = new MailMessage();

            //receiver, get from text field
            mail.To.Add(txtEmail.Text);

            //sender, by arc tech auto responder
            mail.From = new MailAddress("email@arc.com.sg");

            //email subject
            mail.Subject = "Thank you for your interest in Arc Technologies!";

            //set email body to HTML format
            mail.IsBodyHtml = true;

            //email content
            string htmlMessage = @"<html><body>
                         <img src='http://logo.svg' width='300px' />
                            <br>
                            <br>
                            Hi,
                            <br>
                            <br>
                            Thank you for your interest in Arc Technologies.
                            <br>
                            <br>
                            As soon as our website is ready, you will be notified by email.
                            <br>
                            <br>
                            Kind regards,
                            <br>
                            Management of Arc Technologies
                         </body>
                         </html>";

            //device with html view
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
                                               htmlMessage,
                                               Encoding.UTF8,
                                               MediaTypeNames.Text.Html);

            //device with plain text view
            AlternateView plainView = AlternateView.CreateAlternateViewFromString(
                                              Regex.Replace(htmlMessage,
                                                            "<[^>]+?>",
                                                            string.Empty),
                                              Encoding.UTF8,
                                              MediaTypeNames.Text.Plain);

            //allow html view or plain text view
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);

            //initialize and configure smtp settings


            SmtpClient smtp = new SmtpClient("mail.emailiscool.com.sg", 25);
            smtp.EnableSsl = false;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials =
                 new System.Net.NetworkCredential("helloworld@arc.com.sg", "hallo");

            //send email
            smtp.Send(mail);

            Response.Write("success");
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }

    private void emailArcTech()
    {
        try
        {
            //initialize email object
            MailMessage mail = new MailMessage();

            //receiver, management of arc technologies
            mail.To.Add("whatsup@arc.com.sg");
            mail.To.Add("hows_it_going@arc.com.sg");
            mail.To.Add("have_fun@arc.com.sg");

            //sender, by arc tech auto responder
            mail.From = new MailAddress("email@arc.com.sg");

            //email subject
            mail.Subject = "<Important> " + txtEmail.Text + " wants to get notified about www.arctech.com.sg!!! Please follow up!!!";
            //mail.Subject = "<Testing123> " + txtEmail.Text + " wants to get notified about www.arctech.com.sg!!! Please follow up!!!";

            //set email body to HTML format
            mail.IsBodyHtml = true;

            //email content
            string htmlMessage = @"<html><body>
                         <img src='http://logo.svg' width='300px' />
                            <br>
                            <br>
                            Hi,
                            <br>
                            <br>
                            Please follow up. Thanks.
                            <br>
                            <br>
                            Kind regards,
                            <br>
                            Management of Arc Technologies
                         </body>
                         </html>";

            //device with html view
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
                                               htmlMessage,
                                               Encoding.UTF8,
                                               MediaTypeNames.Text.Html);

            //device with plain text view
            AlternateView plainView = AlternateView.CreateAlternateViewFromString(
                                              Regex.Replace(htmlMessage,
                                                            "<[^>]+?>",
                                                            string.Empty),
                                              Encoding.UTF8,
                                              MediaTypeNames.Text.Plain);

            //allow html view or plain text view
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);

            //initialize and configure smtp settings

            SmtpClient smtp = new SmtpClient("mail.emailiscool.com.sg", 25);
            smtp.EnableSsl = false;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials =
                 new System.Net.NetworkCredential("halloworld@arc.com.sg", "hallo");

            //send email
            smtp.Send(mail);

            Response.Write("success");
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }

    }
}
4

0 回答 0