我正在尝试使用我的电子邮件发送附件,但它似乎无法正常工作。当我不尝试使用附件部分时,我可以发送电子邮件
我正在使用这些导入
Imports System.IO
Imports System
Imports System.Web.Mail
Dim mail As New MailMessage()
mail.To = strTo
mail.From = strFrom
mail.Subject = strSubject
mail.BodyFormat = MailFormat.Html
mail.Body = sBody
'mail.Attachment.Add (strAttachment)
'mail.AddAttachment(strAttachment)
'mail.Attachments.Add(New MailAttachment(strAttachment))
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxxxxxxxxx") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxxxxxxx") 'set your password here
SmtpMail.SmtpServer = "xxxxxxxxxxxx" 'your real server goes here
SmtpMail.Send(mail)
答案 0 :(得分:3)
试试这个
Dim m as new MailMessage
m.Attachments.Add(New Attachment("C:\Test.txt"))
'rest of your code