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 !






How to send E-mail from .NET applications


Posted Date: 19 Jun 2008    Resource Type: Code Snippets    Category: Email
Author: Gaurav AgrawalMember Level: Silver    
Rating: Points: 5



The code sample is written in C# and intends to send mail from .NET applications. The code is implemented as a partial class in C# that extends a Page class. Thus making the code easily reusable.

The method that actually sends the e-mail is an event handler for a button. So, to use this code create a .aspx page with a button, textarea, and corresponding textboxes. Attach this handler to the 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 = "gagrawal@del.aithent.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 = fileupload1.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

Author: Junaid Soomro    09 Nov 2008Member Level: Bronze   Points : 0
Please Create "aspx" file and send complete in zip.
Thanks.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sending E-Mail using .NET  .  Sending E-Mail from C#  .  Send E-Mail from ASP.NET web page  .  Send E-Mail from .net applications  .  

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: Reading mails from microsoftOutlook
Previous Resource: Send Email using Gmail
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use