码迷,mamicode.com
首页 > Web开发 > 详细

ASP.Net 邮箱发送

时间:2020-06-26 22:32:29      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:public   end   ble   lan   vma   send   控制   com   host   

邮件发送的页面

<!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="width: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

ASP.Net 邮箱发送

标签:public   end   ble   lan   vma   send   控制   com   host   

原文地址:https://www.cnblogs.com/XJNB/p/13196348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!