-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewsletter.aspx.cs
More file actions
56 lines (51 loc) · 1.78 KB
/
Copy pathnewsletter.aspx.cs
File metadata and controls
56 lines (51 loc) · 1.78 KB
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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class newsletter : 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 btnNewsletter_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select emailId from WebsiteDetails_Table", con);
toemail = cmd.ExecuteScalar().ToString();
con.Close();
send_mail(txtNewsletter.Text);
}
public void send_mail(string email)
{
con.Open();
StringBuilder sb = new StringBuilder();
sb.AppendLine("Email :- " + email + "<br>");
string to = toemail;
string from = txtNewsletter.Text; //From address
MailMessage message = new MailMessage(from, to);
message.Subject = "Registration for newsletter : ";
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);
con.Close();
}
}