Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.25 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Net;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. //using System.Web.Mail;
  13. using System.Net.Mail;
  14.  
  15. public partial class contactus : System.Web.UI.Page
  16. {
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.  
  20.     }
  21.  
  22.     protected void submit_Click(object sender, EventArgs e)
  23.     {
  24.         try
  25.         {
  26.             string strSubject = "New Contact details dated " + System.DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");
  27.             string strbody = generateBody();
  28.             //string strResp = CommonFunction.SendMail(email0.t
  29.             //string strResp = CommonFunction.SendMail(email0.Text.Trim(), strSubject, strbody);
  30.             //MailMessage msg = new MailMessage();
  31.             MailMessage msg = new MailMessage();
  32.            // string email = "mukeshftec@gmail.com";
  33.             string email = "mansiagrawal123@gmail.com";
  34.             //string txtFrom = "contact@3gsolutions.co.in";
  35.             string txtFrom = "mukeshftec@gmail.com";
  36.             //msg.To = email.Trim();
  37.             msg.To.Add(email);
  38.             //msg.From = txtFrom.Trim();
  39.             msg.From = new MailAddress(txtFrom);
  40.             msg.Subject = strSubject.Trim();
  41.             msg.Body = strbody.Trim();
  42.             //msg.BodyFormat = MailFormat.Html;
  43.             msg.Priority = MailPriority.High;
  44.             SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
  45.            // SMTPServer.Port = 587;
  46.             SMTPServer.Port = 465;
  47.             SMTPServer.Credentials = new System.Net.NetworkCredential("mukeshftec@gmail.com", "anshulkamina");
  48.             SMTPServer.EnableSsl = true;
  49.             //SmtpMail.SmtpServer.Insert(0,"127.0.0.1");
  50.             //SmtpMail.SmtpServer = "smtp.YourProvider.com";
  51.             //SmtpMail.SmtpServer = "smtp.net4india.com";
  52.             //SmtpMail.SmtpServer = "smtp.net4india.com";
  53.             //SmtpMail.SmtpServer = "localhost";
  54.             SMTPServer.UseDefaultCredentials = false;
  55.             SMTPServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
  56.             //SMTPServer.DeliveryMethod=msg
  57.             SMTPServer.Send(msg);
  58.             //if (strResp != "")
  59.             //{
  60.             //    Page.ClientScript.RegisterStartupScript(this.GetType(), "op", "alert('" + strResp + "');", true);
  61.             //}
  62.             //else
  63.             //{
  64.             //Page.ClientScript.RegisterStartupScript(this.GetType(), "op", "alert('Message Sent Successfully.');", true);
  65.             Response.Redirect("Thanks.html");
  66.             //}
  67.         }
  68.         catch(Exception ex)
  69.         {
  70.            // Response.Write();
  71.         }
  72.  
  73.     }
  74.     public string generateBody()
  75.     {
  76.         string strHtml = "<style>.maintable {font-family: Arial, Verdana, Helvetica, sans-serif; color:Silver; font-size:11px;}</style>";
  77.         strHtml += "<table class='maintable' border='0' width='100%' cellspacing='0' cellpadding='0'>";
  78.         strHtml += "<tr>";
  79.         strHtml += "<td colspan='2' align='center' style='color:white;background-color:navy;font-family:Arial; font-size:11px; font-weight:bold;'>New Contact Details</td>";
  80.         strHtml += "</tr>";
  81.         strHtml += "<tr>";
  82.         strHtml += "<td align='left' style='width:20%'>Name:</td>";
  83.         strHtml += "<td align='left' style='width:80%'>" + title.Text.Trim() + " " + firstName0.Text.Trim() + " " + middleName0.Text.Trim() + " " + lastName0.Text.Trim() + " " + "</td>";
  84.         strHtml += "</tr>";
  85.         if (jobTitle0.Text != "")
  86.         {
  87.             strHtml += "<tr>";
  88.             strHtml += "<td align='left'>Job Title:</td>";
  89.             strHtml += "<td align='left'>" + jobTitle0.Text.Trim() + "</td>";
  90.             strHtml += "</tr>";
  91.         }
  92.         if (companyName0.Text != "")
  93.         {
  94.             strHtml += "<tr>";
  95.             strHtml += "<td align='left'>Company Name:</td>";
  96.             strHtml += "<td align='left'>" + companyName0.Text.Trim() + "</td>";
  97.             strHtml += "</tr>";
  98.         }
  99.         if (website0.Text != "")
  100.         {
  101.             strHtml += "<tr>";
  102.             strHtml += "<td align='left'>Website:</td>";
  103.             strHtml += "<td align='left'>" + website0.Text.Trim() + "</td>";
  104.             strHtml += "</tr>";
  105.         }
  106.         if (address3.Text != "")
  107.         {
  108.             strHtml += "<tr>";
  109.             strHtml += "<td align='left'>Address 1:</td>";
  110.             strHtml += "<td align='left'>" + address3.Text.Trim() + "</td>";
  111.             strHtml += "</tr>";
  112.         }
  113.         if (address4.Text != "")
  114.         {
  115.             strHtml += "<tr>";
  116.             strHtml += "<td align='left'>Address 2:</td>";
  117.             strHtml += "<td align='left'>" + address4.Text.Trim() + "</td>";
  118.             strHtml += "</tr>";
  119.         }
  120.         if (city0.Text != "")
  121.         {
  122.             strHtml += "<tr>";
  123.             strHtml += "<td align='left'>City:</td>";
  124.             strHtml += "<td align='left'>" + city0.Text.Trim() + "</td>";
  125.             strHtml += "</tr>";
  126.         }
  127.         //country
  128.         if (ID_country0.SelectedIndex != 0)
  129.         {
  130.             strHtml += "<tr>";
  131.             strHtml += "<td align='left'>Country:</td>";
  132.             strHtml += "<td align='left'>" + ID_country0.SelectedItem.Text.Trim() + "</td>";
  133.             strHtml += "</tr>";
  134.         }
  135.         if (email0.Text != "")
  136.         {
  137.             strHtml += "<tr>";
  138.             strHtml += "<td align='left'>Email-ID:</td>";
  139.             strHtml += "<td align='left'>" + email0.Text.Trim() + "</td>";
  140.             strHtml += "</tr>";
  141.         }
  142.         if (phone0.Text != "")
  143.         {
  144.             strHtml += "<tr>";
  145.             strHtml += "<td align='left'>Phone:</td>";
  146.             strHtml += "<td align='left'>" + phone0.Text.Trim() + "</td>";
  147.             strHtml += "</tr>";
  148.         }
  149.         if (notes0.Text != "")
  150.         {
  151.             strHtml += "<tr>";
  152.             strHtml += "<td align='left'>Notes:</td>";
  153.             strHtml += "<td align='left'>" + notes0.Text.Trim() + "</td>";
  154.             strHtml += "</tr>";
  155.         }
  156.         strHtml += "</table>";
  157.         return strHtml;
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement