Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i use this code to send email using asp and c#
C#
 SmtpClient client = new SmtpClient(???);
 MailMessage mailMessage = new MailMessage();
 mailMessage.From = new MailAddress("senderEmail");
 mailMessage.To.Add("ToEmail");

 mailMessage.Subject = "hi";
 mailMessage.Body = "message";
 mailMessage.IsBodyHtml = true;
client.Send(mailMessage);

but are there any smtp client value can i use it ?
i need it public ?
that i can use it in my local host pc and server hosting
please help me :)
Posted
Updated 13-Dec-14 8:51am
v2
Comments
Zoltán Zörgő 14-Dec-14 16:15pm    
Any progress? If you find my answer of use, feel free to accept it formally.

So you need an SMTP server do pass to the controller?
Well, it depends. You can use gmail for example but youm ight encounter limitations[^]. It will be just fine for testing. Here is how you can use it from code: http://www.dustinhorne.com/post/Sending-Email-With-Google-Mail-and-ASPNET[^]

For a hosted production environment, you should consult your service provider's web page or contact them. They can tell you the parameters and the limitations also.
 
Share this answer
 
Let me intervene here before giving you a solution. Since you're using ASP.NET, why are you using the .NET way of sending the emails. ASP.NET has their own method of sending emails, which makes sending emails in ASP.NET a bit easy and efficient for the developers.

You can read on sending the emails in ASP.NET from my article here: Sending Emails Easily Using ASP.NET Helpers[^]

Secondly, there are many servers that can be used to send the emails to clients. Gmail, Outlook or Yahoo all are the examples of free service providers, which can be used from hosting environment to testing environment and it works in both. I have personally always used the Gmail servers, although I do have Outlook and Yahoo accounts. You should also use these servers and they will work for you. An example code for setting up the environment to send email can be like this one,

C#
// basic settings...
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.UserName = "<youremail@theirserver.com>";
WebMail.Password = "yourpassword";
WebMail.From = "SendersEmail@client.com";
// these are required for these remote servers
WebMail.SmtpPort = 25;
WebMail.EnableSsl = true;


.. then sending the email code is as this one,

C#
WebMail.Send(to: "recipient@example.com",
             subject: "hi",
             body: "message");


.. this would send the email, using above provided settings. This is pretty much easy, as compared to the MailMessage and the SmtpClient class provided in the .NET framework, as you're required to work with NetworkCredentials and other such setup too.
 
Share this answer
 
We have smtp servers linked with google, hotmail and yahoo which can be used
 
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