| To: | |
| Subject: | |
| Body: | |
| Gmail Email: | |
| Gmail Password: | |
======================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Data;
using System.Data.SqlClient;
public partial class email : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = @"Data Source=PC\GAMETAIKO;Initial Catalog=login;Integrated Security=True";
}
protected void SendEmail(object sender, EventArgs e)
{
con.Open();
String query = "INSERT INTO cubaan2 (fromSender, toSender, subjectSender, status) VALUES( '" + txtEmail.Text + "', '" + txtTo.Text + "', '" + txtSubject.Text + "', '" + "' ) ";
SqlDataAdapter SDA = new SqlDataAdapter(query, con);
SDA.SelectCommand.ExecuteNonQuery();
con.Close();
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
}
===================================================================== this is the code i use to do a simple 'send an email using asp.net', i have a few problem.
after the email send, it will store in database the content of the email. Can someone help me, i want the email content in database will be deleted after admin had read it.
Thank you so much.
Dharmraj ThakurPosted May 22, 2017, 4:53 AM