Click here to Skip to main content
15,921,542 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
My code as follows
C#
private void btn_Sendmail_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient smtpserver = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("noreply@himtmarine.com", "reminder mail");
                mail.To.Add("ns@himtmarine.com");
                mail.Subject = "Reminder";
                mail.Body = "mail with attachment";

                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment("E:/Projects/Book1.xls");
                mail.Attachments.Add(Attachment);

                smtpserver.Credentials = new NetworkCredential("ns@himtmarine.com", "himt1234");
                smtpserver.Port = 587;
                smtpserver.EnableSsl = true;

                smtpserver.Send(mail);
                MessageBox.Show("mail send");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }


        }
when i run this code says error as follows
System.Net.Mail.Attachment' is a 'type' but is used like a 'variable'

error shows in below line as follows
mail.Attachments.Add(Attachment);

please help me.

what is the problem. in my code.

Rgds,
Narasiman P
Posted
Updated 18-Jul-13 17:55pm
v2

1 solution

C#
mail.Attachments.Add(Attachment);


Should be:

C#
mail.Attachments.Add(attachment);


Remember c# is case sensitive.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900