include attachment in SMTPMail

Hi,

I would like to ask how to attach a file as an attachment in the mail. i have try but it does not work. however, no error message was produced.

this is my code:

Dim message As New System.Web.Mail.MailMessage

message.To = "li-ching.ooi@avagotech.com"

message.From = txtMail1.Text

message.Subject = txtsubject.Text

message.Body = txtMsg.Text

message.Attachments.Add(txtAttach.Text)

'Try

' SmtpMail.Send(message)

Try

SmtpMail.SmtpServer = "relay.smtp.avagotech.net"

SmtpMail.Send(message)




Answer this question

include attachment in SMTPMail

  • Jeffrey D. Baker - MS

    Thanks Friend! It works already.

  • denis kahl

    i have try to apply those code in that website but it still does not work in my program. Is there anything else that i can do

  • NewToExpress

    Is txtAttach.text the full path to the file And is the email actually being sent and received, but the attachment is missing - is that the problem

  • 勇敢的心

    That code works just fine - what doesnt work - does it give you any errors if so what errors

    What version of VB are you using - VB2003/2005/Express


  • VisualDBA

    Yap. I already attach a very small file (20kb) only. however, it still the same.

  • Aaron Humphrey

    there were no error message. i put my code in try/catch method but also no error. but it skips several codes and jump to those codes after the end try.

    i am using visual studio 2003 to develop my system by writing the codes in vb.net.



  • Toni T

    Try this:

    Dim message As New System.Web.Mail.MailMessage

    message.To = "li-ching.ooi@avagotech.com"

    message.From = txtMail1.Text

    message.Subject = txtsubject.Text

    message.Body = txtMsg.Text

    Dim ATCH as MailAttachment = new MailAttachment(txtAttach.text)

    message.Attachments.Add(ATCH)


  • kbarlar

    Most email servers nowadays block attachments that are considered dangerous. Or too large. Try attaching a small .txt file.



  • JohnCronin

    You should probably validate that the file specified in txtAttach.text actually exists. Also, remember you need the full path with the filename.

    Jim Wooley
    http://devauthority.com/blogs/jwooley/default.aspx



  • Tinu

    The file sure exist 1 because i let the user choose from the build in browse function.

  • Shifarad

    The following has an example of just what your looking for.

    http://www.freevbcode.com/ShowCode.asp ID=5486


  • include attachment in SMTPMail