|
-
Oct 11th, 2011, 05:07 PM
#1
Thread Starter
Frenzied Member
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.
-
Oct 11th, 2011, 07:32 PM
#2
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?
-
Oct 12th, 2011, 06:54 AM
#3
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|