Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Attachment error

Status
Not open for further replies.

JontyMC

Programmer
Nov 26, 2001
1,276
GB
I'm dynamically creating an Excel file using ODBC (server doesn't have Excel installed). This works fine. The problem comes when I try to email it. I set up a basic email which works fine:
Code:
MailMessage m = new MailMessage();
m.From = aParams["emailFrom"];
m.To = aParams["emailTo"];
m.Subject = "Subject";
m.Body = body;
m.BodyFormat = MailFormat.Text;

SmtpMail.Send(m);
Now I add the attachment:
Code:
MailMessage m = new MailMessage();
m.From = aParams["emailFrom"];
m.To = aParams["emailTo"];
m.Subject = "Subject";
m.Body = body;
m.BodyFormat = MailFormat.Text;

MailAttachment xls = new MailAttachment(fileName); 
m.Attachments.Add(xls);

SmtpMail.Send(m);
And it breaks. I get this error:
Code:
Exception occurred:Could not access 'CDO.Message' object.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x800C000D): The specified protocol is unknown.

   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
The specified protocol is unknown.
Any ideas?

Jon

"I don't regret this, but I both rue and lament it.
 
Exception occurred:Could not access 'CDO.Message' object
That seems to suggest that the mail message is failing (not necessarily because there is an attachment). Can you send the message if you don't include the attachment?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, without these 2 lines it works fine:
Code:
MailAttachment xls = new MailAttachment(fileName); 
m.Attachments.Add(xls);

Jon

"I don't regret this, but I both rue and lament it.
 
Try putting a Try/Catch statement around the code and read the InnerException message (it may be further down the exception tree so trace though all of the inner exceptions) as I suspect the reall error will be masked.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top