Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
this is code :-
C#
try
{
    MailMessage mailmsg = new MailMessage();
    SmtpClient smp = new SmtpClient("smtp.gmail.com");
    mailmsg.From = new MailAddress("[EMAIL_Removed]@gmail.com");
    string to = "[EMAIL_Removed]@gmail.com";
    string sub = "Data Work";
    string mes = System.DateTime.Now.ToString("dd/MM/yyyy") + "Sending mail to  from sender User Name:" + txtname + "  Email:" + txtemail.Text + " Moblie No:" + txtmobile.Text + "   Message: " + txtmsgg.Text + " Organization=" + txtorganization.Text + " Website=" + txtwebsit.Text + " project=" + ddrproject.SelectedValue + " TimeLine=" + ddrtimeline.SelectedValue + " Budget="+ddrbught.SelectedValue+"";
    mailmsg.To.Add(to);
    mailmsg.Subject = sub;
    mailmsg.Body = mes;
    smp.Port = 587;
    smp.Credentials = new System.Net.NetworkCredential("[EMAIL_Removed]@gmail.com", "example");
    smp.EnableSsl = true;
    mailmsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

    smp.Send(mailmsg);
    lblmss.Text = " Thanks for contact us";
}
catch (Exception)
{
}

but this code is not working
please Help Me for send email after Successfully registration?
thanks


[Edit member="Tadit"]
Corrected formatting and/or grammatical issues.
Added pre tags.
[/Edit]
Posted
v2
Comments
Sinisa Hajnal 13-Oct-14 8:14am    
Not working how? Do you get an error? Everything goes smoothly except the mail never goes away? What?
Member 10506503 18-Oct-14 6:18am    
sir
no error occured?
no message provied after saving the data.
please help me
thanks

Refer my previous answer sending email to gmail from asp.net[^].

You will get the full working code.

Let me know if you are still getting any issues. In that case, post the exception message as well.
 
Share this answer
 
v2
try this one..

protected void btnSend_Click(object sender, EventArgs e)
{
try
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(txtMailFrom.Text, txtMailTo.Text, txtSubject.Text, txtBody.Text);
/* In case of adding CC and BCC
MailAddress bcc = new MailAddress(txtBcc.Text);
MailAddress cc = new MailAddress(txtCC.Text);
mailMessage.Bcc.Add(bcc);
mailMessage.CC.Add(cc);
*/
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(mailMessage);
Response.Write("<script>alert('Mail Sent')</script>");
}
catch (Exception ex)
{
throw ex;
}
}

And in the Configuration file add this

XML
<system.net>

        <mailSettings>
            <smtp>
                <network host="" port="" userName="" password=""/>
            </smtp>
        </mailSettings>
    </system.net>
 
Share this answer
 
C#

XML
Use  ‘using System.Net.Mail;’

      /// <summary>
      /// Method to send mail.
     /// </summary>
      /// <param name="mailTo">Recipient's Email-Id</param>
      /// <param name="User">Recipient's User Name </param>
      /// <returns>true if mail sent; otherwise, false.</returns>
      private Boolean SendMail(String mailTo, String User)
      {
          Boolean sendMailResult;
          try
          {
              SmtpClient smtpServer = new SmtpClient();
              smtpServer.Credentials = new System.Net.NetworkCredential("", ""); //Add sender’s Email-Id and Password here.
              smtpServer.Port = 25;
              smtpServer.Host = "smtp.gmail.com";
              MailMessage alertMail = new MailMessage();
              alertMail.From = new MailAddress(""); //Add Sender’s Email-Id.
              alertMail.Subject = "Alert Mail";
              alertMail.To.Add(mailTo);
              alertMail.Body = "Dear " + User + "," + Environment.NewLine + " Please Check";
              smtpServer.Send(alertMail);
              sendMailResult = true;
              return sendMailResult;

          }
          catch (Exception ex)
          {
              string exceptionMessage=ex.Message;
              sendMailResult = false;
              return sendMailResult;
          }
          finally
          {

          }

      }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900