m_evergreen
asked on
trouble with sending email attachment from windows application
Error:
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.innerexcept ion is "The specified protocol is unknown."
I experimented, removing the attachment references and the error goes away, however this doesn't get the attachment sent. My code for sending the mail with attachment looks like this:
Dim attachment As New System.web.mail.MailAttach ment(filen ame)
Dim Message As New System.Web.Mail.MailMessag e
Message.To = " <m_evergreen@yahoo.com>"
Message.From = "Order System <m_evergreen@yahoo.com>"
Message.Body = "Attachment: text file"
Message.Subject = "Your Request"
Message.Attachments.Add(at tachment)
System.Web.Mail.SmtpMail.S mtpServer = "mail.company.local"
System.Web.Mail.SmtpMail.S end(Messag e)
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.
An unhandled exception of type 'System.Web.HttpException'
Additional information: Could not access 'CDO.Message' object.
innerexception is "Exception has been thrown by the target of an invocation."
innerexception.innerexcept
I experimented, removing the attachment references and the error goes away, however this doesn't get the attachment sent. My code for sending the mail with attachment looks like this:
Dim attachment As New System.web.mail.MailAttach
Dim Message As New System.Web.Mail.MailMessag
Message.To = " <m_evergreen@yahoo.com>"
Message.From = "Order System <m_evergreen@yahoo.com>"
Message.Body = "Attachment: text file"
Message.Subject = "Your Request"
Message.Attachments.Add(at
System.Web.Mail.SmtpMail.S
System.Web.Mail.SmtpMail.S
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.
ASKER
Since it works fine without the attachment I don't believe the SmtpServer is the cause of the problem. There seems to be something about the attachment which is causing the problem.
The final error, or innerexception, is "The specified protocol is unknown."
The final error, or innerexception, is "The specified protocol is unknown."
if the problem is only the attachment, then you should check that the correct right are setted to the folder containing that files.
have a look on this:
http://www.systemwebmail.com/faq/4.3.6.aspx --->Part 1
http://www.systemwebmail.com/faq/4.3.7.aspx --->Part 2
http://www.systemwebmail.com/faq/4.3.6.aspx --->Part 1
http://www.systemwebmail.com/faq/4.3.7.aspx --->Part 2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.GetCurrentDirect ory()
filename = direct & tbl.Rows(A)("CustomerID") & tbl.Rows(A)("FilterID")
& ".txt"
I hope this will help anyone in a similar situation.
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.GetCurrentDirect
filename = direct & tbl.Rows(A)("CustomerID") & tbl.Rows(A)("FilterID")
& ".txt"
I hope this will help anyone in a similar situation.
glad to see that you find it, the part 2 from my post above point you to do the same as you did.
the point is that one can only create a MailAttachment by specifying an absolute path.
for anybody else that read this thread, for an asp .net app must be used the absolute path too:
//ASP.NET app, absolute path created with Server.MapPath property
MailAttachment a = new MailAttachment( Server.MapPath("test.txt") );
m.Attachments.Add( a );
//console and winform app
MailAttachment a = new MailAttachment( "c:\\test.txt" );
m.Attachments.Add( a );
the point is that one can only create a MailAttachment by specifying an absolute path.
for anybody else that read this thread, for an asp .net app must be used the absolute path too:
//ASP.NET app, absolute path created with Server.MapPath property
MailAttachment a = new MailAttachment( Server.MapPath("test.txt")
m.Attachments.Add( a );
//console and winform app
MailAttachment a = new MailAttachment( "c:\\test.txt" );
m.Attachments.Add( a );
I that dont help look at this comment i have found somewhere:
"...whenever you get the message "Could not access 'CDO.Message' object." message. the true problem is hidden in another message that was produced at a lower level in the application.
To get to this message you have to trap the exception using the following exception description and then print out the complete exception to find the buried problem..."
Try
SmtpMail.Send(oMsg)
Catch ehttp As System.Web.HttpException
MessageBox.Show(ehttp.ToSt