zoukankan      html  css  js  c++  java
  • ASP.Net 邮箱发送

    邮件发送的页面

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <link href="bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet" />
    <script src="Scripts/jquery-3.4.1.min.js"></script>
    <script src="Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script>
    function SendMails() {
    var obj = {
    RecMails:$("#txt_RevMail").val(),
    Title:$("#txt_Title").val(),
    BodyContent:$("#ta_Content").val(),
    };
    $.ajax({
    url: "http://localhost:57820/api/Mail/SendMailMethod",
    dataType: "json",
    type: "post",
    data: obj,
    success: function (data) {
    if (data > 0) {
    alert("发送成功!");
    }
    }
    })
    }
    </script>
    </head>
    <body>
    <div align="center">
    <table class="table table-bordered" style="50%;">
    <tr>
    <th>标题:</th>
    <td><input id="txt_Title" type="text" /></td>
    </tr>
    <tr>
    <th>收件人:</th>
    <td><input id="txt_RevMail" type="text" /></td>
    </tr>
    <tr>
    <th>正文:</th>
    <td><textarea id="ta_Content" rows="4" cols="40"></textarea></td>
    </tr>
    <tr>
    <td colspan="2"><input id="btn_Send" type="button" class="btn btn-primary" value="发送邮件" onclick="SendMails()" /></td>
    </tr>
    </table>
    </div>
    </body>
    </html>

    邮件发送的控制器

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using G6.WeekTwo.Models;
    namespace G6.WeekTwo.Controllers
    {
    public class MailController : ApiController
    {
    [HttpPost]
    public int SendMailMethod(EmailModel model)
    {
    //List<string> list = new List<string>() {
    // "691805617@qq.com",
    // "31900477@qq.com"
    //};
    try
    {
    string[] arr = null;
    if(model.RecMails.Contains(","))
    {
    arr = model.RecMails.Split(',');
    }else
    {
    arr = new string[] { model.RecMails };
    }
    SendMail mail = new SendMail(arr, "31900477@qq.com", model.BodyContent, model.Title, "sfeamvgjafykbgdh");
    mail.Send();
    return 1;
    }
    catch (Exception ex)
    {
    return 0;
    }
    }
    }
    }

    邮件发送的类

    请在这个链接查询

    https://www.cnblogs.com/freedomlan/p/13184891.html

  • 相关阅读:
    一次聚类引发的一系列问题(工作经验篇)
    SQLServer数据库返回错误的国际化
    记一次SQL优化
    java设计模式-工厂模式(springweb为例子)
    JAVA中的泛型(Generic)
    spring源码分析-core.io包里面的类
    java设计模式-代理模式
    javaWeb正则表达式
    Java中的泛型
    关于API,前后端分离
  • 原文地址:https://www.cnblogs.com/XJNB/p/13196348.html
Copyright © 2011-2022 走看看