Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on a button click i need to send username and password to an email id ....how can i do that
Posted
Updated 9-Jan-14 19:11pm
v2
Comments
Er Daljeet Singh 10-Jan-14 1:14am    
post the code what you have done..
Member 10500918 10-Jan-14 3:40am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new ("dnscubes7@gmail.com", "niya4422@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
client.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com","msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
}
}

Replace your user name and password in the mail.Body
Replace your from and to mail addresses.
C#
protected void Button1_Click(object sender, EventArgs e)
       {


           MailMessage mail = new ("from mail address", "to mail address");
           SmtpClient client = new SmtpClient();
           client.Port = 25;
           client.DeliveryMethod = SmtpDeliveryMethod.Network;
           client.UseDefaultCredentials = false;
           client.Host = "smtp.google.com";
           client.Credentials = new System.Net.NetworkCredential("Your EmailID ","password");
           mail.Subject = "this is a test email.";
           mail.Body = "this is my test email body";
           client.Send(mail);
       }


Reference :Send e-mail via SMTP using C#[^]
 
Share this answer
 
v3
Comments
Member 10500918 10-Jan-14 2:53am    
i'm getting an error at client.Send(mail); that failure sending mail
Sibasisjena 10-Jan-14 3:11am    
Check my updated solution. I have added one more line to solution.
client.Credentials = new System.Net.NetworkCredential("Your EmailID ","password");
Member 10500918 10-Jan-14 3:41am    
this is my code i'm still getting errors..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new ("dnscubes7@gmail.com", "niya4422@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
client.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com","msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
}
}
Sibasisjena 10-Jan-14 4:52am    
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage("dnscubes7@gmail.com", "niya4422@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
client.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com","msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
}
Sibasisjena 10-Jan-14 4:52am    
Use this one
you can check this similar posts, you will get tons of information

How To Send Email With ASP.NET C#[^]

how to send email using asp.net C#[^]

after u got some idea to send mail in asp.net. you can use the below code add the username and password to the body of the mail.
C#
protected void BtnSendMail_Click(object sender, EventArgs e)
       {
           string username = "somename@some.com";
           string password = "5omePa55W0Rd";
           string body = string.Format("User Name:{0}\nPassword:{1}", username, password);
           // code to send mail...
           /*
            .
            * .
            * .
            * .
            */

       }
 
Share this answer
 
You can also check this one

how to send mail including attachment[^]
 
Share this answer
 
Comments
Member 10500918 10-Jan-14 3:46am    
this is my code and i'm getting errors..can u pls help me


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{



MailMessage mail = new ("dnscubes7@gmail.com", "niya4422@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
client.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com","msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
}
}
Sumit_Pathak 10-Jan-14 4:16am    
just check this if you found any error then tell us which error you are getting

protected void Button1_Click(object sender, EventArgs e)
{


MailMessage mail=new MailMessage();

// MailMessage mail = new ("dnscubes7@gmail.com", "niya4422@gmail.com");
//here you can set only one email address which means sending mail from your email id
mail.From = new MailAddress("dnscubes7@gmail.com", "niya4422@gmail.com");
mail.To.Add("ss@ss.com");//this is user email address

SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.google.com";
smtp.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com","msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "Here is your username and password :" + txtname.Text + "</br>" + txtpass.Text + "";
smtp.Send(mail);
}
Member 10500918 10-Jan-14 4:39am    
i still gor an error at smtp.Send(mail); that Failure sending mail.



can u pls give the namespaces that i should use
Sumit_Pathak 10-Jan-14 4:53am    
MailMessage mail = new MailMessage();

// MailMessage mail = new ("dnscubes7@gmail.com", "niya4422@gmail.com");
//here you can set only one email address which means sending mail from your email id
mail.From = new MailAddress("dnscubes7@gmail.com", "dnscubes7@gmail.com");
mail.To.Add(txtname.Text);//this is user email address

SmtpClient smtp = new SmtpClient();
smtp.Port = 587;

smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("dnscubes7@gmail.com", "msquaredrupeshjisha");
mail.Subject = "this is a test email.";
mail.Body = "Here is your username and password :" + txtname.Text + "</br>" + txtpass.Text + "";
smtp.Send(mail);
use this gmail server instead of google and i use same namespaces which you mentioned earlier in your code
Member 10500918 10-Jan-14 5:12am    
now the error is this
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. wp8sm16152106pbc.26 - gsmtp

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