-2

I am trying to send automated email when ever some body register on my website. There is no exception whenever I register myself on website (Local server) . I also added using system.Net.Mail and web.Config script a. Following is my piece of ASP.NET code:

 public void SendWelcomeMail()
    {
        string EmailTO = TextBoxEmail.Text;
        string EmailFrom = "exampleEmail@gmail.com";
        string Pass = TextBoxPassword.Text;
        try
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(EmailFrom);

            message.To.Add(new MailAddress(EmailTO));

            message.Subject = "Welcome";
            message.Body = "You are now registered with your email ID "+EmailTO;
            message.Body = "Your Password is "+Pass;
            SmtpClient client = new SmtpClient();
            client.Send(message);
        }
        catch
        {
            Response.Write("Sorry there is an exception. Some thing must be wrong");
        }
}
Ibtisam Tanveer
  • 107
  • 1
  • 10
  • 4
    Since you did not specify a parameter for the SmtpClient() constructor, it is looking for the host, port and credentials in the application settings or the system configuration files. Did you remember to configure either of these? – Diego Bauleo Mar 13 '15 at 18:13
  • No I just totally forgot to set host,port other things to be added in SmtpClient constructor. I understand why I was unable to send email. Thank you. – Ibtisam Tanveer Mar 13 '15 at 18:28

1 Answers1

2

You need an SMTP Host to send an email. You've created a client, but the client can't send an email without a host. You can pass the host as a parameter in the constructor, or assign it to the Host property on the SmtpClient class

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.host(v=vs.110).aspx

Matthew Frontino
  • 496
  • 2
  • 12