How do websites send email when new replies are posted to a question

How do websites send email when new replies are sent to a question, for example, if you answer this question, I get an automated email that my question has an answer to?

+2


a source to share


4 answers


The recipients don't matter as long as you have access to the SMTP server. The code looks something like this, you can get a lot more just by emailing Google.



using System.Net.Mail;
...

var msg = new MailMessage();
msg.From = new MailAddress("me@my.com");
msg.To.Add("you@yours.com");
msg.Subject = "Blah";
msg.Body = "Stuff";
var smtp = new SmtpClient("smtpServerNameOrAddress");
smtp.Send(msg);

      

+2


a source


It depends on the type of server used,

for example if you are using Apache and PHP you can use SendMail to send emails

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



Here's some sample code:

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

mail.From = new MailAddress("username@gmail.com");
mail.To.Add("abc@def.com");
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);

      

+1


a source


Similarly, email clients send mail; they connect to an SMTP server and tell it to send a message. Some / most languages ​​have built support for this kind of thing; for example PHP has a functionmail()

0


a source


Finding MailMessage and SmtpClient classes in .Net

0


a source







All Articles