Results 1 to 3 of 3

Thread: Sending Email using C#.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Sending Email using C#.

    can someone tell me ?Why i am getting the following error .When i tries to compile the following .Thanks in Advance.Error 1 'System.Net.Mail.MailMessage.Subject' is a 'property' but is used like a 'method' Error 2 'System.Net.Mail.MailMessage.Body' is a 'property' but is used like a 'method'
    Error 3 No overload for method 'Send' takes '0' arguments
    Code:
     private void SendMail() {
                MailMessage Message=new MailMessage();
                Message.To.Add("[email protected]");
                Message.Subject("Clark Weekly Sales");
                Message.From = new MailAddress("[email protected]");
                Message.Body("Automatic Weekly Sales For Clk Brand");
                SmtpClient smtp = new SmtpClient("mail.alhokair.com.sa");
                smtp.Send();         
            
            
            }
    Last edited by firoz.raj; Oct 11th, 2011 at 05:23 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Sending Email using C#.

    It concerns me that someone with 689 posts doesn't know the difference between a property and a method. Methods are called while properties are set. You obviously know how to set a property because you're already setting the From property. Subject and Body are also properties so they must be set in the same way, i.e. a value assigned to them.

    As for the third error, just like every method, Intellisense would have told you what parameters the Send method has. Just like every method, you could have simply opened the documentation and read to know how to use it. You could have also just read your code and given it some thought. You create an SmtpClient object and then tell it to Send. What is it supposed to be sending?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: Sending Email using C#.

    It concerns me that someone with 689 posts doesn't know the difference between a property and a method. Methods are called while properties are set. You obviously know how to set a property because you're already setting the From property. Subject and Body are also properties so they must be set in the same way, i.e. a value assigned to them.

    As for the third error, just like every method, Intellisense would have told you what parameters the Send method has. Just like every method, you could have simply opened the documentation and read to know how to use it. You could have also just read your code and given it some thought. You create an SmtpClient object and then tell it to Send. What is it supposed to be sending?
    sorry jimmy i did not notice that it is property .so thanks to notify me my mistake.
    so know it is ok
    Code:
    private void SendMail(){        
                MailMessage Message = new MailMessage();
                Message.To.Add("[email protected]");
                Message.Subject="Clark Weekly Sales";
                Message.From = new MailAddress("[email protected]");
                Message.Body=("Automatic Weekly Sales For Clk Brand");
                SmtpClient smtp = new SmtpClient("mail.alhokair.com.sa");
                smtp.Send(Message);
    
    
            }
    Last edited by firoz.raj; Oct 12th, 2011 at 07:08 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width