ASP.NET - file upload and send to mail - Asked By sunil pandey on 08-Feb-12 07:22 AM

Hi all

i want to upload file and send to mail.but only file path is going to mail
dipa ahuja replied to sunil pandey on 08-Feb-12 07:25 AM
using System.Net.Mail;
using System.Net;
protected void btnSent_Click(object sender, EventArgs e)
  string toEmailAddress="";
  string GmailId="";
  string password="";
  string bodyMsg="helo its testing mail";
  MailMessage mail = new MailMessage();
  mail.From = new MailAddress(GmailId);
  mail.Subject = txtSubject.Text;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
  //Attach file using FileUpload Control and put the file in memory stream
  if (FileUpload1.HasFile)
    mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
  SmtpClient smtp = new SmtpClient("");
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
Dilip Sharma replied to sunil pandey on 08-Feb-12 07:25 AM
try this 
Somesh Yadav replied to sunil pandey on 08-Feb-12 07:26 AM
hi you just gothrough the below link so that you will understand and you can do on your own
D Company replied to sunil pandey on 08-Feb-12 07:57 AM
Hello Friend,

Assuming here that u already have working code to sen an email from you application, now come to the requirement instead of sending the file you want to send the filepth, its ok. but make sure that reciever should have right to access the file also .

You can do somthing like this

string fileName = Path.GetFileName(YourFileUploadControl.PostedFile.FileName);

now send this string as anattachment or in the mail body as per your convinient.

Hope it helps!!