[C#] Send Mail

Come spedire una mail con C# .net?

Framework 2.0

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]using System.Web.Mail;

[…]

MailMessage mail = new MailMessage();

mail.To = "to@email.it";
mail.From = "da@email.it";
mail.Subject = "ciao!!!";
mail.BodyFormat = MailFormat.Html;
mail.Body = "<b>Testo</b> del messaggio!";

SmtpMail.SmtpServer = "tuo.smtp.com";
SmtpMail.Send(mail);[/code]

Framework 3.5:

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]using System.Net.Mail;

[…]

MailMessage mail = new MailMessage();

mail.To.Add("mail0@site.it");
mail.CC.Add("mail1@site.it");
mail.CC.Add("mail2@site.it");

mail.From = new MailAddress("noreply@site", "NAME");
mail.Subject = "[AUTO] Mail automatica";

mail.Body = "(Mail automatica)\n\nTesto…";

SmtpClient smtp = new SmtpClient("smtp.site.it");

try { smtp.Send(mail); }
catch  { }[/code]

tutto qui!!!

Alberto Pasca
Latest posts by Alberto Pasca (see all)