2012-10-10 2 views
2

특정 위치에 있고 특별히 이름이 지정된 첨부 파일 ("C : \ New \ Log.txt")특정 파일 이름이 아닌 폴더에 여러 첨부 파일 보내기 ...

그러나 주어진 폴더의 모든 첨부 파일이 포함 된 전자 메일을 보낼 수 있기를 바랍니다. 모든 변수 설정은 my.settings를 사용하여 프로젝트의 다른 위치에서 구성되었으며 폴더 대상인 my.settings.fileloc1과 비슷합니다.

아래는 현재 코드입니다. 꽤 getfiles가 포함될 것이라고 확신하지만 비어있는 상태에서 실행 중입니다. 제발 도와주세요! 당신이 :)

답변

0
' ... 
For Each filePath As String In Directory.GetFiles(My.Settings.FileLoc1) 
    Dim Attach As New Net.Mail.Attachment(filePath) 
    mail.Attachments.Add(Attach) 
Next 
SmtpServer.Send(mail) 
' ... 
+0

그게 전부의 great..works 마법처럼 S에있는 모든 파일을 찾고 For Each 루프를 시도 – user1735404

2

가지고 올 수 아무것도

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Try 
     Dim SmtpServer As New SmtpClient() 
     Dim mail As New MailMessage() 
     SmtpServer.Credentials = New _ 
     Net.NetworkCredential(My.Settings.SMTPuser, My.Settings.SMTPuser) 
     SmtpServer.Port = My.Settings.SMTPPort 
     SmtpServer.Host = My.Settings.SMTPHost 
     mail = New MailMessage() 
     mail.From = New MailAddress(My.Settings.from) 
     mail.To.Add(My.Settings.recipient) 
     mail.Subject = My.Settings.subject 
     mail.Body = My.Settings.body 
     Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment("C:\New\Log.txt") 
     '^^The above needs to be an actual file 
     '^^I want it to select all files in a given folder and attach them! 
     mail.Attachments.Add(Attach) 
     SmtpServer.Send(mail) 
     MsgBox("Mail Sent") 
    Catch ex As Exception 
     MsgBox("Email Settings are either incomplete or incorrect" & vbNewLine & "Please see below details:" & vbNewLine & vbNewLine & ex.ToString) 
    End Try 

End Sub 

덕분에 ystem.IO.Directory.GetFiles()

관련 문제