0

请告诉我使用telerik rad upload在邮件中附加文件并发送邮件。我尝试了不同的方案将文件附加到邮件中,但没有附加。

这是场景:我使用目标文件夹将其保存在网络服务器上并从该位置附加文件。

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);
              }
            }

我也尝试使用 Telerik 页面中的演示示例来执行此操作,但它没有锻炼。请帮我。

谢谢, 色拉万提

4

1 回答 1

0
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);

                    }
                }
于 2012-06-12T12:54:45.977 回答