Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

 

I am using SMTP to send an email

I want to attach a text file to this but I dont know how to define it so that it gets attached correctly...

 

Dim msgMail As New MailMessage()

Dim stbMessageBody As New System.Text.StringBuilder()

dim strFileLocation = Server.MapPath("") & "\Bonus-" & Format(Date.Now, "dd-MM-yyyy") & ".txt"

 

Try

'CREATE MESSAGE BODY stbMessageBody.Append(strBody)

 

msgMail.From = fromID

msgMail.To = To_Email

msgMail.Body = "Bonus Orders"

msgMail.Subject = strSubject

msgMail.Attachments.Add(TextFile????) <-- Problem

SmtpMail.SmtpServer = strIPAddress

SmtpMail.Send(msgMail)

 

Catch ex As Exception

Throw ex

End Try

 

 

hopefully someone can help ..

thank

ZuBiE

Posted

Figured it out .. or I found it on the net :)

 

Add this to the code above

 

Dim attAttachment As MailAttachment

 

attAttachment = New MailAttachment(strFileLocation)

 

msgMail.Attachments.Add(attAttachment)

 

 

hope this helps someone else

ZuBiE

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...