-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.aspx.cs
59 lines (55 loc) · 2.02 KB
/
contact.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class contact : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString);
public static string toemail = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnContact_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("select emailId from WebsiteDetails_Table", con);
toemail = cmd1.ExecuteScalar().ToString();
send_mail(username.Text, useremail.Text, usermsg.Text);
username.Text = "";
useremail.Text = "";
usermsg.Text = "";
con.Close();
}
public void send_mail(string username, string email, string usermessage)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("User name :- " + username + "<br>");
sb.AppendLine("User email :- " + email + "<br>");
sb.AppendLine("User message :- " + usermessage + "<br>");
string to = toemail;
string from = useremail.Text; //From address
MailMessage message = new MailMessage(from, to);
message.Subject = "Inquirey for Ananya Fashion : ";
message.Body = sb.ToString();
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Gmail smtp
System.Net.NetworkCredential basicCredential1 = new
System.Net.NetworkCredential("omopyt2020@gmail.com", "jjkhsulyfsbgdvks");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
client.Send(message);
}
}