<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/9198417524264281132?origin\x3dhttp://threeart3949.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Monday, April 2, 2007

How to Programatically Send an eMail through ASP.NET 2.0 and C#

There are several ways to programatically send an email from a given web site. It depends on what platform and what language you are using.

I am not going to describe in this article what should be done in Java or PHP; I will try to reserve each language in a separate article.

This code shows the code behind a push button that could be added to a form of type aspx. Just add a push button; label it with the wanted description like "Send message now"; double-click the button; and finally, copy and paste this code to the click event handler of the push button. Surely, the aspx form should have some text boxes, radio buttons, check boxes, combo boxes, lists, and labels asking the user to fill them out. Do not forget the validition control that would help a lot in filtering the wrong input.

protected bool SendMessageAsEmail()
{

bool RetVal = true;

MailMessage objEmail = new MailMessage();

objEmail.To.Add("toemail@somewebsite.com");

objEmail.From = new MailAddress("fromemail@somewebsite.com");

objEmail.Subject = "Message from a visitor";

objEmail.Body = "this is the body of the message";

objEmail.Priority = MailPriority.High; // if you want to change the priority; else, remove this line


try

{

SmtpClient smtp = new SmtpClient("mailserver.com");

smtp.Port = 5544; // if port has a specific value; else, remove this line

smtp.EnableSsl = false;

smtp.Credentials = new NetworkCredential("emailAccountName", "emailAccountPassword");

smtp.Send(objEmail);

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

RetVal = false;

}

return RetVal;
}

For any question, do not hesitate to contact me on:

Andre Showairy
writing@imagesti.com
http://www.imagesti.com
Computer Scientist since 1991.
In programming since 1991.
In C++ programming since 1993.
Long experience in VB, C#, VB.NET, ASP.NET, and ADO.NET.
Founder and owner of IT Images - http://www.imagesti.com

Article Source: http://EzineArticles.com/?expert=Andre_Showairy

Farm
Snakeskin Wallets
Mobile Home Holidays
Article Career Counseling Free Journal
Farm
Advisor Estate Home Msn Real
Gas
House
1773 Act Tea
Brookfield Condo
Farm
Gas
Woodbridge Nj Home For Sale
Swarovski Bead Wholesales
Snow Tire Wheels
Country Country Decorating Essential Florkes Home House Living Living Randy
Home Kb Lawsuit
Area Carpet Carpet Contemporary Rug Rug Rug Rug Rugs
Hot Dog Halloween Costume
Dvd Ipod Movie
Newspaper Obituary Province Vancouver
House
Mr Coffee Part
Fat Girl On Dirt Bike
Star Trac Spin Bike
6000 Bike Mountain Trek
Chocolate
Shirt
Wholesale Lady Hat
Chocolate
Company Equity Home Loan Mortgage Offer That
Independent Skull Wallet
Toy
Condition Driving Oklahoma
Bike Orion Pit
Carpet Cleaning Montreal Rental
Toy
Buying A Home After Bankruptcy
Wholesales Cosmetics
House
House
Business Construction Loan
Medical
Real Estate As A Career
Toy
Medical
Bed Day Skirt
Michigan Commercial Construction Company
Snow Leopard Pictures
In Snow Tubing Virginia
Bank California Job Oxnard
Business Home Job Work
Coffee Break Arcade
Farm
House
Career Planning Services
Home For Sale Randleman North Carolina
Orange County Bikers
House
Alice In Wonderland Tea Party
Dying Carpet
Chinese Herbal Tea
Shirt
Medical
Mens Bikers
Bed Tanning Wolf

0 Comments:

Post a Comment

<< Home