2

特定の場所にあり、具体的に名前が付けられた添付ファイル (「C:\New\Log.txt」) を含む電子メールを送信できました。

ただし、名前に関係なく、特定のフォルダー内のすべての添付ファイルを含むメールを送信できるようにしたいと考えています。すべての変数設定は、my.settings を使用してプロジェクト内の別の場所で構成されます。フォルダーの宛先、つまりファイルの場所として my.settings.fileloc1 についても同様の設定が必要です。

以下は私の現在のコードです。私はそれがgetfilesを含むと確信していますが、空で実行しています....助けてください!

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

あなたが思いつくことができるものをありがとう:)

4

2 に答える 2

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)
' ...
于 2012-10-10T16:43:56.200 に答える