Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

unable to send attachment via asp.net vb smtpserver

$
0
0

Hi, I have a pdf file in my webhost server. I want to send this file as attachment when visitor key in their email and click the send button.

the following is my code to send email, it works well without this line "mail.Attachments.Add(attachFile)"....

Dim attachfile As System.Net.Mail.Attachment

Dim SmtpServer As New Net.Mail.SmtpClient
Dim mail As New Net.Mail.MailMessage
SmtpServer.Host = "my smtp server"
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New System.Net.NetworkCredential("my email", "my password")

mail.From = New Net.Mail.MailAddress("my email")
mail.To.Add("visitor email")
mail.Subject = "my email subject"
mail.IsBodyHtml = True
mail.Body = "my email body"

attachfile = New System.Net.Mail.Attachment("~/folder/file name")

mail.Attachments.Add(attachFile)

SmtpServer.Send(mail)

What should i do in order to be able to send the file in my server as attachment?

thanks in advance

garf


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>