i have two email id in different column.
i wan to send email on both id this possible or not.
CREATE TABLE [dbo].[MESSAGE_SYSTEM] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[VEND_EMP] VARCHAR (50) NULL,
[VEN_EMP_NAME] VARCHAR (50) NULL,
[PARTICULARS] VARCHAR (50) NULL,
[AMT] VARCHAR (50) NULL,
[VEN_EMP_PHNO] VARCHAR (50) NULL,
[VEN_EMP_EMAIL] VARCHAR (50) NULL,
[EIC_PH_NO] VARCHAR (50) NULL,
[EIC_MAIL_ID] VARCHAR (50) NULL,
[flag] VARCHAR (3) DEFAULT ('N') NULL,
[date_time] DATETIME DEFAULT (getdate()) NULL
);
namespace WebApplication13
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void btnSendMail_Click(object sender, EventArgs e)
{
string Id = string.Empty;
DataTable dt = new DataTable();
try
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb.Checked == true)
{
if (cb != null && cb.Checked)
{
//get Current EMAIL_ID from the DataKey
Id = Convert.ToString(GridView1.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("select VEN_EMP_EMAIL,EIC_MAIL_ID from MESSAGE_SYSTEM where Id=" + Id + "", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
//Fill datatable with EMAIL_ID corresponding to Current EMP_ID
adp.Fill(dt);
//Get EMAIL_ID into variable
string emailId = dt.Rows[0]["VEN_EMP_EMAIL"].ToString();
string Email_id1 = dt.Rows[0]["EIC_MAIL_ID"].ToString();
//write code to send mail
SendEmailUsingGmail(emailId);
SendEmailUsingGmail(Email_id1);
dt.Clear();
dt.Dispose();
}
}
}
// ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Emails sent successfully');", true);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
Id = string.Empty;
}
}
//private void SendEmailUsingGmail(string toEmailAddress)
private void SendEmailUsingGmail(string toEmailAddress, string AMT, string PARTICULARS)
{
try
{
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("indradeo7306@gmail.com", "7503431478");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
MailMessage message = new MailMessage();
message.From = new MailAddress("indradeo7306@gmail.com");
message.To.Add(toEmailAddress);
message.Subject = " PAYMENT INFORMATION";
//message.Body = "Amount of Rs " + AMT + " for " + PARTICULARS + " is sent to your Bank account";
smtp.Send(message);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
try
{
SmtpClient smtp = new SmtpClient();
Page.RegisterStartupScript("UserMsg", "<script>alert('Payment Details Successfully Send...');if(alert){ window.location='WebForm2.aspx';}</script>");
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
Page.RegisterStartupScript("UserMsg", "<script>alert('Payment Details Sending Failed...');if(alert){ window.location='WebForm2.aspx';}</script>");
}
}
}
}