2015-02-10 157 views
0

我有一個頁面,電子郵件可以發送多個附件。這裏是我的代碼通過ASP上傳文件:AjaxFileUpload控件調用ajaxUpload1vb.net電子郵件發送和接收,但沒有附件

Protected Sub ajaxUpload1_OnUploadComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AjaxFileUploadEventArgs) 

    Dim filePath As String = "~/Uploads/" & Convert.ToString(e.FileName) 

    ' Save upload file to the file system 
    ajaxUpload1.SaveAs(MapPath(filePath)) 

    e.PostedUrl = Page.ResolveUrl("~\uploads\" + e.FileName) 
    Try 
     emailAttachment = New System.Net.Mail.Attachment(filePath) 
     attahchemnts.Add(emailAttachment) 
    Catch ex As Exception 
     Label2.Text = ex.ToString 
    End Try 


End Sub 

​​是由所有上傳的文件名列表。

而且該位負責在按鈕單擊事件

Try 
      If ajaxUpload1.HasAttributes Then 

       For counter As Integer = 0 To attahchemnts.Count 
        mail.Attachments.Add(attahchemnts.Item(counter)) 

       Next 

      End If 
     Catch ex As Exception 
      Label2.Text = ex.ToString 
     End Try 

問題設置郵件的附件是我能夠成功發送和接收電子郵件,但我看不到電子郵件附件。任何人都有線索?由於

回答

0

這是我如何成功地做到這一點

var m = new MailMessage { Subject = txtSubject.Text, IsBodyHtml = true, Body = emailOpeningLine + txtMessage.Text }; 

      try 
      { 
       m.To.Add(new MailAddress(dr[0].ToString().Trim())); 
       m.From = new MailAddress(txtUserName.Text); 
       foreach (var attachment in Attactments) 
       { 
        m.Attachments.Add(new Attachment(attachment)); 
       } 
       client.Send(m); 
       m.To.Clear(); 
       m.Attachments.Clear(); 
       Success.Add(dr[0].ToString()); 
      } 
      catch (SmtpException esException) 
      { 
       Errors.Add("Error sending to " + dr[0].ToString() + " " + esException.Message); 
      } 
      catch (Exception ex) 
      { 
       Errors.Add("Error sending to " + dr[0].ToString() + " " + ex.Message); 

      } 

在這個例子中,我有串與是循環通過添加到郵件附件的位置列表C#版本。

我也有一個成功和失敗的名單,以便它繼續失敗,然後我拿起任何錯誤後。

您應該能夠使用telerik code轉換器

相關問題