以下是使用附件发送邮件的简单代码: / ******************* * /
Dim msgMail As New System.Web.Mail.MailMessage
Dim rcpName As String
Dim client As New SmtpClient
Dim i As Integer
Dim recips_addr() As String = Split(to_address, ";")
Dim recips_name() As String = Split(to_name, ";")
For i = 0 To recips_addr.Length - 1
rcpName = """" & recips_name(i) & """"
msgMail.To = rcpName & recips_addr(i) & ";"
Next
msgMail.From = from_address
msgMail.Subject = subject
msgMail.BodyFormat = System.Web.Mail.MailFormat.Html
msgMail.Body = message
msgMail.BodyEncoding = System.Text.Encoding.UTF8
If String.IsNullOrEmpty(attachment_path) Then attachment_path = "NONE"
If (attachment_path <> "NONE") Then
Dim att As New System.Web.Mail.MailAttachment(attachment_path)
msgMail.Attachments.Add(att)
End If
If send_to_sender Then
msgMail.Bcc = from_address
End If
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = My.Settings.smtp_Server
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = My.Settings.emailUsername
msgMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = My.Settings.emailPassword
System.Web.Mail.SmtpMail.Send(msgMail)
/ ********************************************** **** /
现在,查询是我使用上面的代码发送pdf文件作为附件,文件名是'Report_出生地_出生地_出生地_6023.pdf'。 当我收到收件箱中的邮件时,该文件的名称变为“Report ____ 6023.pdf”。 我不知道为什么附件文件名正在改变。 请帮忙!!!!