C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Sending E-Mail from Web Applications


Posted Date: 18 Jun 2008    Resource Type: Articles    Category: Web Applications

Posted By: Gaurav Agrawal       Member Level: Silver
Rating:     Points: 8



The code sample is a C# program that aims to send an e-mail from a web application. The SendingMail class in the below example inherits the Page class and the mail is sent on Button's Click event.


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Web.Mail;
public partial class SendingMail : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
// Sending mail using Code..
MailMessage mm = new MailMessage();
try
{
mm.From = "gau.agrawal1982@gmail.com";
mm.To = txtTO.Text.ToString();
mm.Cc = txtCC.Text.ToString();
mm.Bcc = txtBCC.Text.ToString();
mm.Body = txtBody.Text.ToString();
mm.Subject = txtSubject.Text.ToString();
string filePath = fload.PostedFile.FileName;
mm.Attachments.Add(new System.Web.Mail.MailAttachment(filePath,MailEncoding.UUEncode));
System.Web.Mail.SmtpMail.Send(mm);

lblMessage.Text = "Email successfully sent.";
}
catch(Exception ex)
{
lblMessage.Text = "Send Email Failed." + ex.Message;
}

}
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sending Mail in .NET  .  Sending Mail from Web Applications  .  Send Mail from Web Application  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Using SQLCacheDependency Class ASP.Net and SQL server 2005
Previous Resource: what is the difference between server.transfer and response.redirect?
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use