2013-03-05 2 views
0

안녕하세요서버 쪽 제출 버튼에 경고 메시지 추가

전자 메일을 보내려면 asp.net을 사용하고 있습니다. 'inquire'또는 'submit'버튼을 누르면 이메일이 전송되지만 사용자에게 이메일이 전송되었다는 확인을 보내는 방법을 모르겠습니다.

어떻게하면됩니까?

HTML :

<tr><td colspan="2"><asp:Button class="btn btn-success" ID="ButtonEnquire" OnClick="Button1_Click" runat="server" Text="Enquire" /></td></tr> 

서버 측 코드 뒤에 : 시스템을 사용하여

; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;

namespace Contact.Secure 
{ 
    public partial class Corporate : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
      { 
       PopulateDropDownTypeofCards(); 
      } 
      //DropDownTypeofCards.DataSource = Enums.EnumList.CreateList(typeof(Enums.ContactMethodTypes)); 
      //DropDownList1.DataTextField = "EnumDescription"; 
      //DropDownList1.DataValueField = "EnumValue"; 

      //DropDownList1.DataBind(); 
     } 

     private void PopulateDropDownTypeofCards() 
     { 
      DropDownTypeofCards.DataSource = Enums.EnumList.CreateList(typeof(Enums.CardTypes)); 
      DropDownTypeofCards.DataTextField = "EnumDescription"; 
      DropDownTypeofCards.DataValueField = "EnumValue"; 

      DropDownTypeofCards.DataBind(); 
     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      var html = string.Format("<html><head></head><body>{0}<br/>{1}<br />{2}<br />{3}<br />{4}<br />{5}</body></html>", TextBoxName.Text, TextBoxEmailAddress.Text, TextBoxCompanyName.Text, TextBoxCompanyAddress.Text, TextBoxPhoneNumber.Text, TextBoxAmiuntofCardstoSubscribe.Text, DropDownTypeofCards.Text); 



      SendEmail(System.Configuration.ConfigurationManager.AppSettings["ContactUsFormSubmission"].ToString(), "Form Submission", html, true, "[email protected]", true, 587); 

     } 

     public static void SendEmail(string toEmail, string subject, string body, bool isHTML = false, string fromAddress = null, bool enableSSL = false, int SSLPort = 465, string[] Attachment = null) 
     { 


      try 
      { 
       if (bool.Parse(System.Configuration.ConfigurationManager.AppSettings["SendEmail"].ToString())) 
       { 
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); 

        message.To.Add(toEmail); 
        message.Subject = subject; 

        if (string.IsNullOrEmpty(fromAddress) || string.IsNullOrWhiteSpace(fromAddress)) 
        { 
         message.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["SMTPFromAddress"].ToString()); 
        } 
        else 
        { 

         message.From = new System.Net.Mail.MailAddress(fromAddress); 
        } 

        message.IsBodyHtml = isHTML; 

        message.Body = body; 

        if (enableSSL) 
        { 

        } 

        if (Attachment != null) 
        { 
         if (Attachment.Count() > 0) 
         { 
          foreach (string a in Attachment) 
          { 
           System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(a); 

           message.Attachments.Add(attachment); 
          } 
         } 
        } 
        System.Net.Mail.SmtpClient smtp; 
        if (enableSSL) 
        { 
         smtp = new System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString(), SSLPort); 
         smtp.UseDefaultCredentials = false; 
        } 
        else 
        { 
         smtp = new System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SMTPServer"].ToString(), SSLPort); 
         smtp.UseDefaultCredentials = false; 
        } 

        smtp.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["SMTPUser"].ToString(), System.Configuration.ConfigurationManager.AppSettings["SMTPPassword"].ToString()); 

        smtp.EnableSsl = enableSSL; 

        smtp.Timeout = 60000; 


        try 
        { 
         smtp.Send(message); 
        } 
        catch 
        { 
         throw; 
        } 
       } 
      } 
      catch (Exception) 
      { 
       throw; 
      } 
     } 


    } 
} 
+0

이 자습서를 읽어야합니다. http://weblogs.asp.net/bleroy/archive/2005/12/01/asp-net-alerts-how-to-display-message-boxes-from-server-side- code.aspx – freshbm

답변

1

당신은 성공적인 메일에 이메일 전송에 대한 귀하의 방법이 코드를 추가 할 수는

var message = "Email has been sent"; 

string script = "<script language=\"javascript\" type=\"text/javascript\">;alert('" + message + "');</script>"; 

ScriptManager.RegisterStartupScript(Page, this.GetType(), "AlertMessage", script, false); 

그것은 귀하의 메시지와 함께 경고 자바 스크립트를 표시합니다 보냈다.

+0

감사합니다. 매력을 발휘합니다. 당신의 도움을 주셔서 감사합니다 – DextrousDave

관련 문제