mugsey
asked on
Good example of email helper class to send email
I need to send email using c# .net 3.5. Now I want to encapsulate all of this in a class - I greately need example please
Thanks you
Thanks you
ASKER
Thank you
What is the best way to encapsulate this in class - I want to have a class method "sendEmail" and pass in paramters
What is the best way to encapsulate this in class - I want to have a class method "sendEmail" and pass in paramters
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.ba
message.To.Add(new MailAddress("recipient1@fo
message.To.Add(new MailAddress("recipient2@fo
message.To.Add(new MailAddress("recipient3@fo
message.CC.Add(new MailAddress("carboncopy@fo
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
System.Net.Mail reads SMTP configuration data out of the standard .NET configuration system (so for ASP.NET applications youd configure this in your applications web.config file). Here is an example of how to configure it:
<system.net>
<mailSettings>
<smtp from="test@foo.com">
<network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
Hope this helps,