include attachment in SMTPMail  
Author Message
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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.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)




Visual Basic8  
 
 
spotty





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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

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


 
 
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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

 
 
nobugz





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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



 
 
spotty





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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


 
 
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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.



 
 
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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

 
 
jwooley





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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



 
 
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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

 
 
weirdbeardmt





PostPosted: Visual Basic General, include attachment in SMTPMail Top

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

 
 
rSchild





PostPosted: Visual Basic General, include attachment in SMTPMail Top

Try this:

Dim message As New System.Web.Mail.MailMessage

"

message.From = txtMail1.Text

message.Subject = txtsubject.Text

message.Body = txtMsg.Text

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

message.Attachments.Add(ATCH)


 
 
LynnOoi





PostPosted: Visual Basic General, include attachment in SMTPMail Top

Thanks Friend! It works already.