我设法发送了一封电子邮件,其附件位于特定位置并专门命名(“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
感谢您提出的任何建议:)