Reply
SmtpClient Mail.Send
Old 10-31-2007, 08:42 AM SmtpClient Mail.Send
pjb007's Avatar
Super Talker

Posts: 100
Location: UK
I am trying to get an ASP.NET email form to run using C#

Here is my code:
Code:
SmtpClient Mail = new SmtpClient("smtp.mydomain.com");
        Mail.Send("myemail@ddress.com", txtEmail.Text,
                  txtName.Text, txtMessage.Text, txtPref.Text);
When I run that I get the following error message:
Quote:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1501: No overload for method 'Send' takes '5' arguments
If I take out txtName or txtMessage or txtPref it works, is there a way to get it to work with all of them?
__________________
pjb007
pjb007 is offline
Reply With Quote
View Public Profile Visit pjb007's homepage!
 
When You Register, These Ads Go Away!
     
Old 10-31-2007, 03:50 PM Re: SmtpClient Mail.Send
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
No ...
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-31-2007, 04:16 PM Re: SmtpClient Mail.Send
pjb007's Avatar
Super Talker

Posts: 100
Location: UK
It seems strange that you cant send send more than five things.
__________________
pjb007
pjb007 is offline
Reply With Quote
View Public Profile Visit pjb007's homepage!
 
Old 10-31-2007, 04:38 PM Re: SmtpClient Mail.Send
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Quote:
Compiler Error Message: CS1501: No overload for method 'Send' takes '5' arguments
Why strange??

put the error message and the fact that taking out one item works and you have your answer.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-31-2007, 04:41 PM Re: SmtpClient Mail.Send
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
or maybe if you read

SmtpClient.Send Method
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-01-2007, 06:50 AM Re: SmtpClient Mail.Send
pjb007's Avatar
Super Talker

Posts: 100
Location: UK
I've just tried another method of sending emails run the programme and that only takes 4 arguments.

Why does it limit the number of fields you can have?
__________________
pjb007
pjb007 is offline
Reply With Quote
View Public Profile Visit pjb007's homepage!
 
Old 11-01-2007, 07:01 AM Re: SmtpClient Mail.Send
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
because that is what it is designed with.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-19-2007, 10:19 PM Re: SmtpClient Mail.Send
Novice Talker

Posts: 7
Use System.Web.Mail.MailMessage class

Quote:
Originally Posted by pjb007 View Post
I am trying to get an ASP.NET email form to run using C#

Here is my code:
Code:
SmtpClient Mail = new SmtpClient("smtp.mydomain.com");
        Mail.Send("myemail@ddress.com", txtEmail.Text,
                  txtName.Text, txtMessage.Text, txtPref.Text);
When I run that I get the following error message:


If I take out txtName or txtMessage or txtPref it works, is there a way to get it to work with all of them?
webspinner is offline
Reply With Quote
View Public Profile
 
Old 01-19-2008, 04:47 AM Re: SmtpClient Mail.Send
Junior Talker

Posts: 4
You have to create a MailMessage object and add everything you need to that, then use the MailMessage object in the send method:

SmtpClient _smtp = new SmtpClient();
MailMessage _mm = new MailMessage();
_mm.From = new MailAddress(_strFrom);
_mm.To.Add(new MailAddress(_strTo));
_mm.Subject = _strSubject;
_mm.IsBodyHtml = true;
_mm.Body = _strBody;
_smtp.Send(_mm);
__________________
http://www.WebsiteInvestors.co.uk - Secure financial investment for your new or existing website
WebInvestors is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to SmtpClient Mail.Send
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.17317 seconds with 13 queries