how do i write some codes to send email from
an .aspx page? thanks.
Printable View
how do i write some codes to send email from
an .aspx page? thanks.
You need to reference the System.Web.Mail namespace for that to work. Also you need to check which SMTP server you can use to send the message (in most cases it is localhost though).Code:MailMessage mail = new MailMessage();
mail.From = "[email protected]";
mail.To = "[email protected]";
mail.Subject = "This is the subject";
mail.Body = "This is the message";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
This might help too -> http://www.aspheute.com/english/20000918.asp
HTH
DJ
might need this too...interesting =)
Hellow,
I'm looking for a way to mail in the background.. I tried this but it wont work.. Is there anything I maybe forgot?
greetz
nickname
You can check the following
1) In the above code the SMTP server being used is "localhost".
This means that the server hosting your ASP.Net application is itself the SMTP server. If this is not the case then replace "localhost" by the SMTP address or the IP address of the SMTP server to be used.Code:SmtpMail.SmtpServer = "localhost";
2) Check to see what authentication method you are using for the application. It can be possible that the user may not be authenticated for the SMTP server. Add the following code to specify some more details before sending the mail.(This code is in c#)
Hope this helps.Code://Set Mode to basic authentication
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//set your username here
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "userName");
//set your password here
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
//set the SMTP server port number here. Default is 25
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
Nikhil