try
{
byte[] bytes;
MailMessage email = new MailMessage();
email.From = new MailAddress("<sourcr email address>");
email.To.Add("<destination email address>");
email.Subject = "Mail Testing";
email.Body = "You are Successfully Created Profile......";
string constr = ConfigurationManager.ConnectionStrings["fishbowlConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT UserName FROM Email";
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytes = Encoding.ASCII.GetBytes(sdr["UserName"].ToString());
MemoryStream pdf = new MemoryStream(bytes);
Attachment data = new Attachment(pdf, "example.txt", "text/plain");
email.Attachments.Add(data);
}
con.Close();
}
}
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("<source email address>", "<source email password>");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.Send(email);
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
No comments:
Post a Comment