Sending mail Programmatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I wonder... How can I send mail programmatically using c# ? Any pointers/samples will be appriciated

Nadav.
 
Nadav,

Take a look in the System.Web.Mail namespace. It will have classes
there (particularly the MailMessage class) which you can use to send mail
programatically.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nadav said:
Hi,

I wonder... How can I send mail programmatically using c# ? Any
pointers/samples will be appriciated.
 
Hi,

You can use MailMessage class from System.Web. Even it;s in that namespace
it can be used to send mail no matter what kind of application you have.

Here is some code of how to generate an email with an attachment.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


protected void SendByMail(string file)
{
MailMessage MyMail = new MailMessage();
MyMail.From = "(e-mail address removed)";
MyMail.To = ((CtpUser)Session["SystemUser"]).Email;
MyMail.Subject = "Web-CTP Report";
MyMail.Body = " Attached is the report requested";
MyMail.BodyEncoding = Encoding.ASCII;

MailAttachment MyAttachment = new MailAttachment(file);
MyMail.Attachments.Add(MyAttachment);


SmtpMail.SmtpServer =
System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"];
SmtpMail.Send(MyMail);

}


Nadav said:
Hi,

I wonder... How can I send mail programmatically using c# ? Any
pointers/samples will be appriciated.
 
Back
Top