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="xx@gmail.com";
  string GmailId="abc@gmail.com";
  string password="";
  string bodyMsg="helo its testing mail";
 
  MailMessage mail = new MailMessage();
  mail.To.Add(toEmailAddress);
 
  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.gmail.com");
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
  smtp.Send(mail);
}
 
Dilip Sharma replied to sunil pandey on 08-Feb-12 07:25 AM
try this


http://www.systemnetmail.com/faq/4.4.aspx 


http://www.codeproject.com/Articles/8528/ASP-NET-email-with-multiple-attachments 
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


http://www.csharpaspnetarticles.com/2009/10/send-email-with-attachment-in-aspnet.html
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!!
Regards
D