0

hii i m trying to send mail through coding of asp

is there any external APIs to send mail like JAVA

give some hints if possible sample code!!

I m using vs 2005 as well as vs 2008

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
Hussain
  • 927
  • 1
  • 16
  • 21

2 Answers2

3

You could use the SmtpClient class. Example using GMail's SMTP:

var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("youraccount@gmail.com", "secret");

var mail = new MailMessage();
mail.From = new MailAddress("youraccount@gmail.com");
mail.To.Add("youraccount@gmail.com");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);

UPDATE: Example with yahoo:

var client = new SmtpClient("smtp.mail.yahoo.com", 587);
client.Credentials = new NetworkCredential("youraccount@yahoo.com", "secret");

var mail = new MailMessage();
mail.From = new MailAddress("youraccount@yahoo.com");
mail.To.Add("destaccount@gmail.com");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Try this:

using System.Web.Mail;
private void SendMessage()

{

MailMessage mail = new MailMessage();

mail.To = txtTo.Text;

mail.From = txtFrom.Text;

mail.Subject = txtSubject.Text;

mail.Body = txtBody.Text;

SmtpMail.SmtpServer = "localhost";

SmtpMail.Send(mail);

}

if want to send attachment

Add the following code

mail.Attachments.Add(new MailAttachment(@"C:\myFile.txt"));
BreakHead
  • 10,480
  • 36
  • 112
  • 165