我已成功发送一封带有附件的电子邮件,该附件位于特定位置且专门命名(“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
感谢您提出的任何建议:)
最佳答案
尝试 For Each循环查找 S ystem.IO.Directory.GetFiles() 中的所有文件
关于vb.net - 通过电子邮件发送文件夹中的多个附件,而不仅仅是特定的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823413/