views:

84

answers:

4

How do websites send email when new answers is posted to question like if you answer this question, I will get automated email that my question has an answer?

A: 

The same way mail clients send mail; they make a connection to an SMTP server and tell it to send the message. Some/most languages have built in support for that sort of thing; for example, PHP has the mail() function

Michael Mrozek
Thanks Michael for response. I'm trying to this in .NET. So far, I know we can send such email on gmail only but not on yahoo. is that correct, how do you send email to other than gmail ids?
Elenor
A: 

Lookup MailMessage and SmtpClient classes in .Net

CodeToGlory
+2  A: 

Recipients don't matter, as long as you have access to a SMTP server. Code looks something like this - you can get a whole lot more just by googling .NET send email:

using System.Net.Mail;
...

var msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add("[email protected]");
msg.Subject = "Blah";
msg.Body = "Stuff";
var smtp = new SmtpClient("smtpServerNameOrAddress");
smtp.Send(msg);
Joe Enos
+1  A: 

It depends on the type of server you are using,

for example if you are using Apache and PHP you can use SendMail for sending the mails

and if you are using ASP.NET, you can send it using any free SMTP Server like GMail

Here is a sample code :

SmtpClient smtpobj = new SmtpClient();
MailMessage mail = new MailMessage();

mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Subject";
mail.Body ="<p> Content Here </p>;
smtpobj.Host = "smtp.gmail.com";
smtpobj.Pot = 587;
smtpobj.EnableSsl = true;
smtpobj.Credentials = new NetworkCredential("user", "pass");
mail.Priority = MailPriority.High;
mail.IsBodyHtml = true;
smtpobj.Send(mail);
Sumit Sharma