电子邮件中的多个文件附件

时间:2010-08-28 09:56:50

标签: vb.net

我使用以下代码发送带附件的电子邮件。我可以发送一个附件,但如何发送多个附件?

Dim vrAttachFilePath As String = "c:\users\ittahad\documents\abc.doc"
If vrAttachFilePath.Length > 0 Then
    oMail.Attachments.Add(New Net.Mail.Attachment(vrAttachFilePath))
End If

2 个答案:

答案 0 :(得分:3)

简单地说:

Dim vrAttachFilePathFile1 As String = "c:\users\ittahad\documents\abc.doc"
Dim vrAttachFilePathFile1 As String = "c:\users\ittahad\documents\def.doc"

oMail.Attachments.Add(New Net.Mail.Attachment(vrAttachFilePathFile1))
oMail.Attachments.Add(New Net.Mail.Attachment(vrAttachFilePathFile2))

您只需在每个附件中调用Attachments.Add即可添加任意数量的附件。

答案 1 :(得分:2)

您可以向“附件”集合添加多个元素:

oMail.Attachments.Add(New Net.Mail.Attachment(path1))
oMail.Attachments.Add(New Net.Mail.Attachment(path2))
oMail.Attachments.Add(New Net.Mail.Attachment(path3))
...