using C# .NET to email attachments?????

  • Thread starter Thread starter Duncan Winn
  • Start date Start date
D

Duncan Winn

Is there any way of using C# .NET to create an email with a jpeg attachment
and then send it.

Thanks,

Duncan.
 
Duncan,

Take a look at the classes in the System.Web.Mail namespace. You can
use the MailMessage class to create an email to send. There is also an
Attachments property on the MailMessage class which you can use to attach
files to the email.

Hope this helps.
 
HI Duncan,

Here is some code I'm using to do this:
protected void SendByMail(string file)

{

MailMessage MyMail = new MailMessage();

MyMail.From = "(e-mail address removed)";

MyMail.To = ((CtpUser)Session["SystemUser"]).Email;

MyMail.Subject = "Web-CTP Report";

MyMail.Body = " Attached is the report requested";

MyMail.BodyEncoding = Encoding.ASCII;


MailAttachment MyAttachment = new MailAttachment(file);

MyMail.Attachments.Add(MyAttachment);


SmtpMail.SmtpServer =
System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"];

SmtpMail.Send(MyMail);

}

Hope this help,
 
Thanks very much,

Although I am gerring an error at....
SmtpMail.Send(MyMail);

The error is....

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

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



Any suggestions????

Thanks again,

Duncan.
 
Hi Duncan,


That may mean that you don't have the CDO library installed, or that your
email configuration is not correct, do you have a smtp server that has
permission to send or receive email ?

I would check the email configuration first of all.

Cheers,
 
Duncan,

I did a search on google and in a page I found this :

Note that "Could not access 'CDO.Message' object." is a generic error
message.

To view the actual error try:

ex.InnerException.InnerException.Message


So you should insert a try/catch block to know the real error.


Cheers,
 
Thanks once again!

The error message I now get is...

The "SendUsing" configuration value is invalid

I have no idea what this meas???? any suggestions?
 
Hi Duncan,

Very easy, google it :)
I did and it seems that you are missing setting the SMTP server you need to
use, if you are using localhost you have to set it anyway.

Cheers,
 
Hi Ignacio,

Thanks, I have googled it and I am still a bit bewildered.... (all this is
very new to me)

How do I go about setting the SMTP server. I am on a networked pc, will I
have to go an ask the
network support team the name of the server or is there any other way of
finding this out!
(What does local host mean?)

thanks and best regards,

Duncan.
 
Back
Top