Advertise with us
Control Panel
Forum
Hosting Help
ASP.NET 4.5 & SQL 2012 Hosting
Resources
Notice
Login
Members
Shared Hosting
|
Upgrade
|
Advertise
|
Tutorials
|
Home
»
Resources
»
Sending Mail script
ASP.NET
ADO.NET
Web Services
Remoting
Visual Studio 2005
Error Bank
Interview Questions
Tips & Tricks
XML
HTML
Jscript/Javascript
IIS
Windows
General
Submit Resource or code snippet
... and get
surprise gifts
Win Digital camera, ASP.NET Books, Free softwares!!
Sending Mail script
08 Apr, 2008
Author:
Brian Oburak
Summary
Sending Mail, with a FileUpload control as parameter
.NET Classes used :
Don't forget to include the namespaces:
using System.Net.Mail;
using System.IO;
Ey, here I wrote a method to send an email using a FileUpload as a parameter so as to attach files. So what you just need is to give the ID of the FileUpload to the method and your attachment will be sent.......it is worth mentioning that you can just set the parameter to null...if you don't have anything to attach.
Here we go:
//Send a mail
public static void SendMail(string to, string from, string subj,
string body, FileUpload fileControl)
{
MailAddress sendTo = new MailAddress(to);
MailAddress sendFrom = new MailAddress(from);
MailMessage msg = new MailMessage(sendFrom, sendTo);
msg.Subject = subj;
msg.Body = body.Replace("\n", "
");
msg.IsBodyHtml = true;
if (fileControl != null)
{
string fname = Path.GetFileName(fileControl.PostedFile.FileName);
Attachment attach = new Attachment(fileControl.FileContent, fname);
msg.Attachments.Add(attach);
}
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(msg);
}
Feedbacks about this page from members:
- No Feedbacks yet !! -
Submit Feedback
View All Feedbacks
Total
members
:
250640
Average new registrations per day (in last 7 days):
7
New Registration:
Open
Register Now
Talk to Webmaster
Tony John
Facebook
Google+
Twitter
Advertise
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies Pvt Ltd.
All Rights Reserved.