vbscript [.net] [vb]从目录发送带有文件附件的电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript [.net] [vb]从目录发送带有文件附件的电子邮件相关的知识,希望对你有一定的参考价值。
Dim productBrochuresArray As String() = New String(0) {""}
If productBrochures.Length > 1 Then
productBrochuresArray = productBrochures.Split(","C)
For i = 0 To productBrochuresArray.GetUpperBound(0)
productBrochuresArray(i) = Server.MapPath("docs/product/brochures/" + productBrochuresArray(i))
Next
End If
Dim productDataSheetsArray As String() = New String(0) {""}
If productDataSheets.Length > 1 Then
productDataSheetsArray = productDataSheets.Split(","C)
For i = 0 To productDataSheetsArray.GetUpperBound(0)
productDataSheetsArray(i) = Server.MapPath("docs/product/datasheets/" + productDataSheetsArray(i))
Next
End If
Dim productSafetyDataSheetsArray As String() = New String(0) {""}
If productSafetyDataSheets.Length > 1 Then
productSafetyDataSheetsArray = productSafetyDataSheets.Split(","C)
For i = 0 To productSafetyDataSheetsArray.GetUpperBound(0)
productSafetyDataSheetsArray(i) = Server.MapPath("docs/product/safetydatasheets/" + productSafetyDataSheetsArray(i))
Next
End If
' Send email
emailSent = MyEmailProvider.SendProductEmail( _
toAddresses, _
"Parex Product Information", _
bodyText, _
productBrochuresArray, _
productDataSheetsArray, _
productSafetyDataSheetsArray _
)
===================
Public Function SendProductEmail( _
ByVal toAddresses() As String, _
ByVal subjectLine As String, _
ByVal bodyText As StringBuilder, _
ByVal brochureAttachmentFilePathsArray As String(), _
ByVal datasheetAttachmentFilePathsArray As String(), _
ByVal safetyDatasheetAttachmentFilePathsArray As String() _
) As Boolean
SendProductEmail = True
Dim errorStr As String = "None"
Dim i As Integer
Try
Dim mail As MailMessage = New MailMessage()
Dim toAddressesStr As String = String.Empty
For i = 0 To toAddresses.GetUpperBound(0)
If toAddresses(i) IsNot String.Empty Then
toAddressesStr &= toAddresses(i) & ","
End If
Next
toAddressesStr = Mid(toAddressesStr, 1, toAddressesStr.Length - 1)
mail.To.Add(toAddressesStr)
mail.From = New MailAddress(ConfigurationManager.AppSettings("FROMNAME") & " <" & ConfigurationManager.AppSettings("FROMEMAIL") & ">")
'Mail.From = New MailAddress(ConfigurationManager.AppSettings("FROMEMAIL"), ConfigurationManager.AppSettings("FROMNAME"))
mail.Subject = subjectLine
mail.Body = bodyText.ToString()
mail.IsBodyHtml = True
If brochureAttachmentFilePathsArray(0).Length > 0 Then
For i = 0 To brochureAttachmentFilePathsArray.GetUpperBound(0)
mail.Attachments.Add(New Attachment(brochureAttachmentFilePathsArray(i)))
Next
End If
If datasheetAttachmentFilePathsArray(0).Length > 0 Then
For i = 0 To datasheetAttachmentFilePathsArray.GetUpperBound(0)
mail.Attachments.Add(New Attachment(datasheetAttachmentFilePathsArray(i)))
Next
End If
If safetyDatasheetAttachmentFilePathsArray(0).Length > 0 Then
For i = 0 To safetyDatasheetAttachmentFilePathsArray.GetUpperBound(0)
mail.Attachments.Add(New Attachment(safetyDatasheetAttachmentFilePathsArray(i)))
Next
End If
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = ConfigurationManager.AppSettings("SMTP").ToString()
smtp.Port = CInt(ConfigurationManager.AppSettings("SMTPPORT"))
smtp.Credentials = New NetworkCredential(ConfigurationManager.AppSettings("FROMEMAIL"), ConfigurationManager.AppSettings("FROMPWD"))
'smtp.EnableSsl = True
smtp.Send(mail)
Catch ex As Exception
SendProductEmail = False
'errorStr = ex.ToString()
End Try
Return SendProductEmail
End Function
以上是关于vbscript [.net] [vb]从目录发送带有文件附件的电子邮件的主要内容,如果未能解决你的问题,请参考以下文章