Click here to Skip to main content
15,890,391 members
Please Sign up or sign in to vote.
3.50/5 (3 votes)
See more:
I WANT TO SEND MAIL BY USING ASP.NET AND C#.NET(3.5)

BUT I DIDNOT NOT UNDERSTAND WHAT I HAVE TO MENTION IN SMTP SERVER

HERE IS THE CODE

protected void Button2_Click(object sender, EventArgs e)
{
    System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();

    msg.To = TextBox1.Text;
    msg.From = "sharmarun22@gmail.com";
    msg.Subject = TextBox2.Text;
    msg.Body = txtContent.Value;
    lblStatus.Text = "Sending...";

    lblStatus.Text = "Sending...";
    SmtpMail.SmtpServer = "smtp.localhost";
   
    SmtpMail.Send(msg);
    lblStatus.Text = "Sent email (" + TextBox2.Text + ") to " + TextBox1.Text;
}




PLEASE TELL ME THE SYNTEX FOR HOW TO MENSION SERVER NAME AND UID/PWD
Posted
Updated 5-Mar-10 1:58am
v4

Dear Arun,

Make sure you are using System.Net. Tested and the easiest way to send mail is following:
MailMessage MyMM = new MailMessage("fromabc@gmail.com", "toxyz@gmail.com", "subject", "body");
Attachment MyAttachment = new Attachment(filename); 
MyMM.Attachments.Add(MyAttachment);
MyMM.IsBodyHtml= true;
SmtpClient MySC = new SmtpClient("smtp.gmail.com",587);
MySC.EnableSsl=true;
MySC.Send(MyMM);


Do not forget to establish mailsetting in Web.config underlying system.net tag. e.g.

XML
<system.net>
    <mailSettings>
      <smtp from="fromabc@gmail.com" deliveryMethod="Network">
        <network host="smtp.gmail.com" port="587" userName="fromabc@gmail.com" password="1234AA88"/>
      </smtp>
    </mailSettings>
  </system.net>


I hope it will help you.

Regards!
Aman
 
Share this answer
 
v2
Unless you have a mail server on your local box, that won't work.

You probably also need some credentials (userID/password) to send/read mail on your mail server. If you don't need those things, you have no business running a mail server that's exposed to the internet.

Lastly, turn off CapsLock when you enter messages here. It annoys everyone to be yelled at.
 
Share this answer
 
v2
This line;
SmtpMail.SmtpServer = "smtp.localhost";


Really makes no sense, unless you hae a mail server on your local machine.

If you do not have an email server on your local machine you need to set it to a valid mail server like "mail.somehost" or "smtp.somehost".

If you take australias telstra for example it would be "mail.bigpond.com" word of warning this server WILL NOT WORK FOR YOU.
 
Share this answer
 
Hi Friend,

Please Check the following article to send email from gmail account.

http://aspxcode.somee.com/Articles/Send_gmail.aspx
 
Share this answer
 
Hope Send email[^]will help you.
 
Share this answer
 
use this below article. it will support to u...

<a href="http://www.developer.com/article.php/3096831">http://www.developer.com/article.php/3096831</a>[<a href="http://www.developer.com/article.php/3096831" target="_blank" title="New Window">^</a>]
 
Share this answer
 
Comments
velmahesh 6-Jan-11 7:57am    
there is avail the code to email process..
Add Namespace


using System.Net;
using System.Net.Mail;


On Button Click Event


string strmess = "Your User Name:-'" + txtfname.Text + "' ; Your Password:-'" + txtpass.Text + "'";

SmtpClient smtpclient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
message.From = new MailAddress("sharmarun22@gmail.com");

message.To.Add("'" + txtEmail.Text + "'");
message.Subject = "Your Password";
message.Body = strmess;
smtpclient.Host = "smpt.gmail.com";
smtpclient.EnableSsl = true;
//smtpclient.UseDefaultCredentials = true;
System.Net.NetworkCredential network = new System.Net.NetworkCredential();
network.UserName = "sharmarun22@gmail.com";
network.Password = "(Your Gmail Password)";
smtpclient.UseDefaultCredentials = true;

smtpclient.Credentials = network;
smtpclient.Port = 25;
smtpclient.Send(message);

}

catch (Exception ex)
{
Response.Write(ex.Message);
}
 
Share this answer
 

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