The specified protocol is unknown. Error while trying to send email with attachment.

M

m_evergreen

Errors:
An unhandled exception of type 'System.Web.HttpException' occurred in
system.web.dll

Additional information: Could not access 'CDO.Message' object.

innerexception is "Exception has been thrown by the target of an
invocation."

innerexception.innerexception is "The specified protocol is unknown."

I experimented, removing the attachment references and the error goes
away, the email is sent, and recieved. My code for sending the mail
with attachment looks like this:

Dim attachment As New System.web.mail.MailAttachment(filename)
Dim Message As New System.Web.Mail.MailMessage
Message.To = " <[email protected]>"
Message.From = "Order System <[email protected]>"
Message.Body = "Attachment: text file"
Message.Subject = "Your Request"
Message.Attachments.Add(attachment)
System.Web.Mail.SmtpMail.SmtpServer = "mail.company.local"
System.Web.Mail.SmtpMail.Send(Message)

I'm beginning to suspect that the problem may stem from this actually
being a windows application instead of a web application. I imported
System.Web references which includes System.Web.Mail of course. Is
there something else I need in references?

Let me know if more code is needed to troubleshoot. Thank you.
 
M

m_ evergreen

Thank you, I've found a fix for the problem. I started by adding c:/ to
my file name, giving me something like this:

filename = "c:/" & tbl.Rows(A)("CustomerID") & tbl.Rows(A)("FilterID") &
".txt"

This worked on my machine but I was concerned that it might not work on
the server. After giving it some thought I changed the code again
adding to the top:

Imports System.io

and then later in the code:

direct = Directory.GetCurrentDirectory()
filename = direct & tbl.Rows(A)("CustomerID") & tbl.Rows(A)("FilterID")
& ".txt"

I hope this will help anyone in a similar situation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top