开发者

how to send mail in asp.net

hii i m trying to send mail through coding of asp

开发者_JAVA技巧

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


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);


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"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜