send email with web service

I want to ask if any one know how to send email with web service?

I mean, I have a App, and I will ask the user for one mail and a message, and I will resend that message to the email that the user said.

Thanks for your time

Upvotes: 1

Views: 3227

Answers (3)

Thanks I alredy have the answer.

I use the code for send email, and after that I only make a program that every minut call a web service, in that way I can select all the messages that i want to send minute a minute

Upvotes: 0

Rohit Surve
Rohit Surve

Reputation: 140

firstly add following namespace

using System.Web.Mail;

and use following function

public string sendMail()
{
    string status = "";
    try
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(txt_email.Text);

        mail.From = new MailAddress("**********@gmail.com");
        mail.Subject = "Testing";

        string Body = txt_msg.Text;
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address


        smtp.Credentials = new System.Net.NetworkCredential
             ("********@gmail.com", "*********");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);
        status = "Success";

    }
    catch(Exception ex)
    {
        status = "Failure";
        Response.Write(ex.Message + "|" + ex.StackTrace);

    }
    return status;

}

Upvotes: 1

Chan's
Chan's

Reputation: 13

I think you need to do some server side scripting for that, that would be the solution for your issue. also you can check below answer

Best practices for sending automated daily emails from web service

Upvotes: 0

Related Questions