Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

I am a new to .net. I am trying to send a mail to an id which I am able to send successfully. The problem is my code is only accepting txt files as attachments. I also want it to accept the doc files. Please let me know the modifications I have to do.

Here is what I got so far:
VB
Dim sbmail As New StringBuilder
Dim MailMsg As New MailMessage()
MailMsg.To.Add(********)
MailMsg.From = New MailAddress(job_email.Text)
MailMsg.Subject = mail_sub.Text
MailMsg.Body = mail_body.Text
If fu_resume.HasFile Then
  MailMsg.Attachments.Add(New Attachment(fu_resume.PostedFile.InputStream, fu_resume.FileName))
End If
MailMsg.IsBodyHtml = True
Dim SmtpMail As New SmtpClient()
SmtpMail.Host = "smtp.gmail.com"
SmtpMail.Port = 587
SmtpMail.Credentials = New System.Net.NetworkCredential(****, ***)
SmtpMail.EnableSsl = True
SmtpMail.Send(MailMsg)
ClearTextBox(Me)
lblmsg.Text = "Resume Sent Successfully"
Posted
Updated 16-Nov-10 1:02am
v2

Only give filepath in attachment,

MailMsg.Attachments.Add(New Attachment(filePath))
 
Share this answer
 
You have to give the FULLY QUALIFIED path to the file, not just the filename itself. You're code may be assuming that the document is in whatever the "current directory" is.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900