C\#이메일 발송 기능 비밀번호 찾기 또는 리 셋 기능
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Web;
namespace CalslNum.Helper
{
/// <summary>
///
/// </summary>
public class MailService
{
/// <summary>
/// SendMail("[email protected]", " ", "[email protected]", " ", " ", " ", " ", "smtp.126.com", true,);
/// </summary>
/// <param name="from"> </param>
/// <param name="fromname"> </param>
/// <param name="to"> ( )</param>
/// <param name="subject"> </param>
/// <param name="body"> </param>
/// <param name="username"> </param>
/// <param name="password"> </param>
/// <param name="server"> smtp </param>
/// <param name= "IsHtml "> HTML </param>
/// <returns>send ok</returns>
public static bool SendMail(string from, string fromname, string to, string subject, string body, string server, string username, string password, bool IsHtml)
{
//
MailMessage mail = new MailMessage();
try
{
//
mail.From = new MailAddress(from, fromname);
//
mail.To.Add(to);
//
mail.Subject = subject;
//
mail.BodyEncoding = Encoding.Default;
//
mail.Priority = MailPriority.High;
//
mail.Body = body;
// HTML
mail.IsBodyHtml = IsHtml;
//
SmtpClient smtp = new SmtpClient(server, 25);
smtp.UseDefaultCredentials = true;
//
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
// , 163
smtp.UseDefaultCredentials = true;
//
smtp.Credentials = new System.Net.NetworkCredential(username, password);
//
smtp.EnableSsl = false;
smtp.Timeout = 10000;
smtp.Send(mail);
return true;
}
catch (Exception)
{
return false;
}
finally
{
mail.Dispose();
}
}
// URL HTML,
public static string ScreenScrapeHtml(string url)
{
// stream
StreamReader reader = new StreamReader(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream(), System.Text.Encoding.UTF8);
string str = reader.ReadToEnd();
reader.Close();
return str;
}
// plaintxt
public static bool SendText(string from, string fromname, string to, string subject, string body, string server, string username, string password)
{
return SendMail(from, fromname, to, subject, body, server, username, password, false);
}
// HTML
public static bool SendHtml(string from, string fromname, string to, string subject, string body, string server, string username, string password)
{
return SendMail(from, fromname, to, subject, body, server, username, password, true);
}
//
public static bool SendWebUrl(string from, string fromname, string to, string subject, string server, string username, string password, string url)
{
//
return SendHtml(from, fromname, to, subject, ScreenScrapeHtml(url), server, username, password);
}
//
public static bool SendEmailDefault(string ToEmail,string f_username,string f_pass,string f_times)
{
StringBuilder MailContent = new StringBuilder();
MailContent.Append(" ××× :<br/>");
MailContent.Append(" ! ");
MailContent.Append(DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss"));
MailContent.Append(" <a href='#'>×××</a> 。<br/>");
MailContent.Append(" , :<br/><br/>");
string url = "http://www.×××.×××/SignIn/Rest?u=" + f_username + "&s=" + f_pass + "&t=" + f_times; 114 MailContent.Append("<a href='" + url + "'>" + url + "</a><br/><br/>"); 115 MailContent.Append(" ( URL , , 。)"); 116 return SendHtml(ConfigurationManager.AppSettings["EmailName"].ToString(), " ", ToEmail, "××× ", MailContent.ToString(), ConfigurationManager.AppSettings["EmailService"].ToString(), ConfigurationManager.AppSettings["EmailName"].ToString(), ConfigurationManager.AppSettings["EmailPass"].ToString()); // webconfig 。 117 } 118 } 119 }
웹 config 설정 정보
<add key="EmailName" value="××××@163.com"/>
<add key="EmailPass" value="××××"/>
<add key="EmailService" value="smtp.163.com"/>
//설명:이 안의"Email Service"는 당신 이 메 일 을 설정 한 smtp/POP 3/...서비스 와 같 아야 합 니 다.대부분@뒤의 설정 에 따라 설정 합 니 다.163 메 일 로 설 치 했 습 니 다.자신의 필요 에 따라 스스로 설정 할 수 있 습 니 다. 백 스테이지 호출 방법
public ActionResult SendEmail(string EmailName)
{
EmailName = Helper.FI_DesTools.DesDecrypt(EmailName);
if (!Regex.IsMatch(EmailName, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
{
return Content("0");
}
string f_username = "";
string f_pass = "";
string f_times = Helper.FI_DesTools.DesEncrypt(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
List<user> list = (from a in users where a.emailaddress == EmailName select a).ToList();
if (list.Count > 0)
{
f_username = Helper.FI_DesTools.DesEncrypt(list[0].×××);
f_pass = Helper.FI_DesTools.DesEncrypt(list[0].×××);
bool flag = Helper.MailService.SendEmailDefault(EmailName, “×××”,“×××”, “×××”); // ,
if (flag)
{
return Content("true");
}
else
{
return Content("false");
}
}
else {
return Content("false");
}
}
메 일 발송 완료 효과 도 는 다음 과 같 습 니 다:이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.