Mannu Mannu - 1 year ago 106
ASP.NET (C#) Question

how to send email through web api

i am making a windows phone app in which i want to give the forgot password functionality.
the app will send a email to stored email id of the user when he will press on forget password button.
As there is no smtp class available in windows phone , so i want to make a web api which will receive email id(and password) from the app and will send an email to that id.
I am new in web services and have 0 knowledge of this
please guide me how to achieve this task and if anyone can provide the code, there must be some web service available like this.

Answer Source

Here is an example of a function that sends an email you can use. Also, there are couple links below that can guide you in creating web service in ASP.NET

In reality, you don’t need to create a web service for this (although it’s recommended). You can create a quick and dirty web form where you pass parameters like this

private static void SendEmail(string from, string from_name, string to, string cc, string bcc, string subject, string body, bool isHtml)
        SmtpClient mailClient = new SmtpClient(Config.SmptSettings.Server);
        mailClient.Credentials = new NetworkCredential(Config.SmptSettings.UserName, Config.SmptSettings.Password);
    mailClient.Port = Config.SmptSettings.Port;

    MailMessage message = new MailMessage();
    if (!string.IsNullOrEmpty(from_name))
        message.From = new MailAddress(from, from_name);
        message.From = new MailAddress(Formatter.UnFormatSqlInput(from));

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

    if (!string.IsNullOrEmpty(cc))

    if (!string.IsNullOrEmpty(bcc))

    message.Subject = subject;
    message.Body = body;
    message.IsBodyHtml = isHtml;

    mailClient.EnableSsl = Config.SmptSettings.SSL;