Email uploaded file as attachment

Thread is closed for posting
7 posts, 0 answers
  1. Brent
    Brent avatar
    22 posts
    Member since:
    Jan 2009

    Posted 07 Feb 2009 Link to this post

    Do you please have an example or instructions for how I can send the uploaded fiel as an attachment instead of just uploading it to a file on the server?

    Thank you very much

  2. Paul
    Paul avatar
    4281 posts

    Posted 09 Feb 2009 Link to this post

    Hello Brent,

    I'm afraid this is out of the scope of the RadUpload control. I'd suggest you make a search on Google for possible solutions.

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Brent
    Brent avatar
    22 posts
    Member since:
    Jan 2009

    Posted 09 Feb 2009 Link to this post

    OohKaay. . .

     So it works like a regular asp:FileUpload control then? I guess that was what I was getting at.
  4. Myriam
    Myriam avatar
    153 posts
    Member since:
    Sep 2008

    Posted 19 Mar 2009 Link to this post

    So it is not possible to do that?
  5. _Haakon_
    _Haakon_ avatar
    3 posts
    Member since:
    Feb 2010

    Posted 08 Feb 2010 Link to this post

                foreach (EmailAttachment attach in attachments) 
                    Attachment attachFile = new Attachment(attachmentsPath + attach.fileName); 
    //Here is the EmailAttacment class I used: 
    public class EmailAttachment 
        public string fileName { get; set; } 
        public string filePath { get; set; } 
        public string attachmentURI { get; set; } 
        public int fileSize { get; set; } 
        public EmailAttachment() 
    //Here is the code I used upon submission of the form to load the generic list: 
            List<EmailAttachment> attachments = new List<EmailAttachment>(); 
            for (int i = 0; i < ruAttachments.UploadedFiles.Count; i++) 
                EmailAttachment attachment = new EmailAttachment(); 
               attachment.filePath = attachmentsPath + ruAttachments.UploadedFiles[i].GetName(); 
               attachment.fileName = ruAttachments.UploadedFiles[i].GetName();  
    Hi Brent,

    You can use the RadUpload tool to get the file names and then have them uploaded to a folder called "attachments". Then create a simple class called EmailAttachments and have it get - set a filename string. Then upon submission of your email form grab the file names from the RadUpload tool and store them in a generic list of EmailAttachment objects. Pass that to your email class and then add this code to add them to your email:

  6. Mike
    Mike avatar
    11 posts
    Member since:
    Jul 2010

    Posted 03 Feb 2011 Link to this post

    Thanks for posting these tips and code. I found that its also possible to take an in-memory file and pass that to the MailMessage without having to first save to disk (by using the UploadedFile.InputStream property):

    <telerik:RadUpload ID="RadUpload1" InitialFileInputsCount="1" MaxFileInputsCount="1" ControlObjectsVisibility="None" runat="server">

    C# code-behind:
    UploadedFile file = RadUpload1.UploadedFiles[0];
    Attachment attachment = new Attachment(file.InputStream, file.FileName);
    MailMessage message = new MailMessage();           
  7. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 20 Feb 2012 Link to this post

    Hello mike ..!
    Could you just send me the full code because an too working on same issue. 

    Thanks & Regards,
Back to Top