简体   繁体   中英

how to attach the file using telerik Rad Async Upload to a mail

Please tell me hoe to attach the file using telerik rad upload in a mail and send the mail. I tried differrent scenarios to attach the file to the mail but it doesn't get attached.

Here is the scenario: I used target folder to save it on the webserver and attach the file from that location.

if (rdtxtAdditionalEmail.Text != "")
            {
                char[] delimiterChars = { ';' };
                string text = rdtxtAdditionalEmail.Text;
                string[] words = text.Split(delimiterChars);
                foreach (string s in words)
                {
                   newEmail.To = dr["Email"].ToString();
                   newEmail.From = "sy@mydomain.com";
                   newEmail.Subject = rdtxtSubject.Text;
                   newEmail.BodyFormat = MailFormat.Html;
                   newEmail.Body = rdtxtSubject.Text;

                   List<EmailAttachment> attachments = new List<EmailAttachment>();
                   foreach (EmailAttachment attach in attachments)
                   {

                      System.Net.Mail.Attachment attachFile = new Attachment("C:/Inetpub  /wwwroot/DotNetNuke/Data/" + attach.fileName);
                    newEmail.Attachments.Add(attachFile);

                   }
                  for (int i = 0; i < rdauAttachments.UploadedFiles.Count; i++)
                  {
                    UploadedFile file = rdauAttachments.UploadedFiles[i];
                    EmailAttachment attachment = new EmailAttachment();
                    attachment.filePath = "C:/Inetpub/wwwroot/DotNetNuke/Data/" + rdauAttachments.UploadedFiles[i].GetName();
                    attachment.fileName = rdauAttachments.UploadedFiles[i].GetName();
                    newEmail.Attachments.Add(attachment);
                 }
                SmtpMail.Send(newEmail);
              }
            }

I also try to do it using the demo exapmle in telerik pages but it didnot workout. Please help me.

Thanks, Sravanthi

string filename = string.Empty;
string path = string.Empty;
MailMessage mailMsg = new MailMessage();
if (AsyncUpload1.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile file in AsyncUpload1.UploadedFiles)
                    {

                        filename = file.FileName;
                        path = System.IO.Path.GetFileName(filename);
                        string Withoutext = System.IO.Path.GetFileNameWithoutExtension(filename);
                        file.SaveAs(Server.MapPath("~/AttachMents/") + path);
                        FileStream fs = new FileStream(Server.MapPath("~/AttachMents/") + filename,
                                   FileMode.Open, FileAccess.Read);
                        System.Net.Mail.Attachment a = new System.Net.Mail.Attachment(fs, filename,
                                   MediaTypeNames.Application.Octet);
                        mailMsg.Attachments.Add(a);

                    }
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM