Skip to content


Configuring SMTP in .Net

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

One of the easiest way to configure a mail service on .NET site is to create a SMTP class and call its function SendMail.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public static class SMTP
{
public static void SendMail(string sFrom, string sTo, string sCC, string sSubject,
string sBODY, bool IsBodyHTML, string sHostName, string sAttachment)
{
try
{
MailMessage message = new MailMessage();
MailAddress address = new MailAddress(sFrom);

message.From = address;
message.To.Add(sTo);
if (sCC != string.Empty)
message.CC.Add(sCC);
message.IsBodyHtml = IsBodyHTML;
message.Body = sBODY;
message.Subject = sSubject;
if (sAttachment != string.Empty)
message.Attachments.Add(new Attachment(sAttachment));

SmtpClient client = new SmtpClient(sHostName, 25);
client.Send(message);
}
catch (Exception Ex)
{

}

}

}


Related Posts:

Posted in ASP.NET, C#, Microsoft .NET.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.