Steven
Steven

Reputation: 61

Sending Mail with Attachment

I am trying to send an attachment with my email however it will not seem to work. I can send email when I do not try and use the attachment section

I am using these imports

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)

Upvotes: 0

Views: 2675

Answers (1)

Jeff
Jeff

Reputation: 918

Try this

Dim m as new MailMessage
m.Attachments.Add(New Attachment("C:\Test.txt"))
'rest of your code

Upvotes: 3

Related Questions