You must Sign In to post a response.
  • Category: ASP.NET

    Using two mail id send the gridview data to mail

    try
    {
    foreach (GridViewRow gv in GDStudents.Rows)
    {
    if (gv.Cells[5].Text != "";)
    {
    EmailChange:
    string fromEmailid = " ";
    if (Email_NO == 1)
    fromEmailid = "vk@gmail.com";
    else if (Email_NO == 2)
    fromEmailid ="rk@gmail.com";
    else
    fromEmailid ="";

    MailMessage mailmess = new MailMessage();
    SmtpClient smtpserver = new SmtpClient("smtp.gmail.com");
    smtpserver.Credentials = new NetworkCredential("vk@hgmail.com","1234");
    smtpserver.Host = "smtp.gmail.com";
    smtpserver.Port = 587;
    smtpserver.EnableSsl = true;
    mailmess.From = new MailAddress("vk@gmail.com","Confirmation");
    mailmess.IsBodyHtml = true;
    mailmess.Subject = "ConfirmationMail";

    string body2 = "<table>";
    body2 = body2 + "<tr><td><b>Dear <font color='Maroon'><b>" + gv.Cells[1].Text.ToString().Trim() + ",</font></td></tr>";
    body2 = body2 + "<tr><td><br/>   <font face='Arial' size='2' color='Navy'><b> " + TxtMessage.Text.ToString().Trim() + " </font></td></tr>";
    body2 = body2 + "</table>";
    mailmess.Body = body2;


    mm.To.Add(new MailAddress(gv.Cells[5].Text.ToString().Trim()));
    Thread threademail = new Thread(delegate()
    {
    sc.Send(mm);
    });
    threademail.IsBackground = true;
    threademail.Start();
    }
    }
    catch (Exception e11)
    { }

    i am sending mail the below Gridview data to send mail.
    txtmessage.text = "Dear Students, Thanks for booking the course";

    In run mode In gridview as follows
    StudentName Email

    Rakesh Rakesh@gmail.com
    Magesh Magesh@gmail.com

    i want to send the mail to rakesh from vk@gmail.com and
    i want to send the mail to Magesh from rk@gmail.com


    i written the code to send mail but i want to send mail to rakesh from vk@gmail.com and i want to send the mail to magesh from rk@gmail.com

    for that how can i do in asp.net using c#.
  • #764179
    In a single commend you can not send email from two from address.

    1. Write Separate method.
    2. Have parameters of from and Toemails.
    3. According to your requirement you can call two times.

    If you want to send email from same smtp server but two different email. Then you have to link your email two emails.

    For this you can refer the following URL
    http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html

    By Nathan
    Direction is important than speed

  • #764187
    Hai Rao,
    Your code looks issue at the below snippet:

    if (gv.Cells[5].Text != "";)
    {
    EmailChange:
    string fromEmailid = " ";
    if (Email_NO == 1)
    fromEmailid = "vk@gmail.com";
    else if (Email_NO == 2)
    fromEmailid ="rk@gmail.com";
    else
    fromEmailid ="";

    Here you are checking Email_NO value, but where you have its value? Is it coming from the GridView? If so then assign its value as:

    if (gv.Cells[5].Text != "";)
    {
    EmailChange:
    Email_NO = int.parse(gv.Cells[5].Text);
    string fromEmailid = " ";
    if (Email_NO == 1)
    fromEmailid = "vk@gmail.com";
    else if (Email_NO == 2)
    fromEmailid ="rk@gmail.com";
    else
    fromEmailid ="";

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764461
    Hi rao,
    Change following line
    mailmess.From = new MailAddress("vk@gmail.com","Confirmation");
    TO
    mailmess.From = new MailAddress(fromEmailid,"Confirmation");
    because you are peoperly assigning fromEmailid depending on Email_NO but immidiately after that you are forcefully changing it to vk@gmail.com

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments