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

1

2 Answers 2

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("[email protected]", "secret");

var mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
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("[email protected]", "secret");

var mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);
Sign up to request clarification or add additional context in comments.

2 Comments

@program-java, yes mail.Tois the receiver and mail.From is the sender. In my example I've used the same account for testing purposes.
okay thanks... if i want to use yahoo instead of gmail then what ill be the Smtp?
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"));

1 Comment

SmtpMail is obsolete. You should use SmtpClient - msdn.microsoft.com/en-us/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.