如何通过asp.net网页API发送电子邮件 [英] how to send email through asp.net web api

查看:530
本文介绍了如何通过asp.net网页API发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作中,我想给忘记密码功能的Windows Phone的应用程序。
应用程序将发送邮件到用户存储电子邮件ID,当他将美元忘记密码按钮p $ PSS。
由于没有在Windows手机可用的SMTP类,所以我希望做一个asp.net网页API,将从应用程序接收电子邮件ID(和密码),并发送电子邮件到该ID。
我在Web服务新有这个0知识
请指导我如何实现这一目标任务,如果有人能提供code,必须有可用的一些像这样的Web服务。

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 asp.net 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.

推荐答案

下面是发送您可以使用电子邮件功能的一个例子。另外,还有一些低于几个链接可以引导您创建的ASP.NET Web服务

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

在现实中,你不必为此创建Web服务(虽然它是推荐的)。在这里您将参数传递这样example.com/sendemail.aspx?account=jack.smith&id=223232343您可以创建一个快速和肮脏的网页表单

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 example.com/sendemail.aspx?account=jack.smith&id=223232343

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);
    }
    else
    {
        message.From = new MailAddress(Formatter.UnFormatSqlInput(from));
    }

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

    if (!string.IsNullOrEmpty(cc))
    {
        message.CC.Add(cc);
    }

    if (!string.IsNullOrEmpty(bcc))
    {
        message.Bcc.Add(bcc);
    }

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

    mailClient.EnableSsl = Config.SmptSettings.SSL;
    mailClient.Send(message); 
}

这篇关于如何通过asp.net网页API发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆