how to send radupload attachments through smtp

Thread is closed for posting
2 posts, 1 answers
  1. Saimadhukar
    Saimadhukar avatar
    31 posts
    Member since:
    Sep 2011

    Posted 21 Oct 2011 Link to this post


    i am working on email functionality and recently i  am using rad uploader to upload files and send to mails through smtp connection ,the problem is if i send notepad  files it is uploading and sending to specified mailid ,but if we upload .pdf or .doc means  pdf or wordformat files e.t.c it is not sending  we are getting an error that file cannot found at path specified .i am sending a code block please reply soon
    void SendEMail()
           if (Session["UserID"] != null) //from home.aspx
               newmailuserid = Convert.ToInt32(Session["UserID"]);
           DbLayer objDB = new DbLayer();
           System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
           if (rdtxtCC.Text != string.Empty)
           Message.Subject = rdtxtSubject.Text;
           Message.Body = rdtxtBody.Text;
           System.Net.Mail.SmtpClient SmtpClient = new System.Net.Mail.SmtpClient("", 587);
           SmtpClient.EnableSsl = true;
           SmtpClient.Credentials = new System.Net.NetworkCredential("", "hits@123");
           System.Net.Mail.MailAddress FromEmail = new System.Net.Mail.MailAddress(TextBox1.Text);
           Message.From = FromEmail;
               System.Net.Mail.Attachment attachment;
               foreach (UploadedFile file in RadUpload1.UploadedFiles)
                       string strFileName = null;
                       strFileName = System.IO.Path.GetFileName(file.FileName);
                       attachment = new System.Net.Mail.Attachment(Server.MapPath(strFileName));
  2. Answer
    Genady Sergeev
    Genady Sergeev avatar
    1600 posts

    Posted 25 Oct 2011 Link to this post

    Hello Saimadhukar,

    The approach that is used is wrong. The FileName property returns the FileName that is on the client-computer. Since your code is executing on the server, there will be no such file as:


    I suggest that you save the file the hard drive first using its SaveAs method and then, using the name you have saved it under, create new Attachment.

    Best wishes,
    Genady Sergeev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top