C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Sending email with an attachment


Posted Date: 07 Feb 2005    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Syed NasrullahMember Level: Bronze    
Rating: 1 out of 5Points: 10



Private void btnClick_ServerClick(object sender, System.EventArgs e)
{
MailMessage objMail = new MailMessage() ;
String strAtt ;
MailAttachment ma;

objMail.From =txtFrom.Text.ToString();
objMail.To = txtTo.Text.ToString() ;
objMail.Subject = txtSubject.Text.ToString() ;

strAtt=txtAttachment.PostedFile.FileName;
strAtt=strAtt.Substring(strAtt.LastIndexOf("\\")+1);
txtAttachment.PostedFile.SaveAs(Server.MapPath(strAtt));

ma =new MailAttachment(Server.MapPath(strAtt));
objMail.Attachments.Add(ma);
objMail.Body = txtBody.Text.ToString() ;
objMail.BodyFormat = MailFormat.Text ;
SmtpMail.Send(objMail) ;

System.IO.File.Delete(Server.MapPath(strAtt));
}


//Add the following code in the web.config file

maxRequestLength="44096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"/>



Responses

Author: Thambidurai    24 Mar 2005Member Level: Bronze   Points : 0
Hi , it was nice article. Anyway i get some problem while trying to download the pdf and open it.
I'm getting an error 'There was an error opening this document. The file is damaged and could not be repaird.' while trying to download the pdf and open it. I have used Cdonts. This problem occurs only occasionally.
Would you please help me to fix this?


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: Performance Improvement in ASP.NET using Caching
Previous Resource: Format DateTime Values in XML
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use