Update MailHelper
This commit is contained in:
@@ -1,15 +1,59 @@
|
||||
using System.Net.Mail;
|
||||
using Furion;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
|
||||
namespace Ewide.Core.Util
|
||||
{
|
||||
public class MailHelper
|
||||
{
|
||||
public string Message { set; get; }
|
||||
public string UserMailAddress { set; get; }
|
||||
/// <summary>
|
||||
/// 邮箱类
|
||||
/// </summary>
|
||||
/// <param name="message">发送的信息</param>
|
||||
/// <param name="userMailAddress">用户的地址</param>
|
||||
public MailHelper(string message, string userMailAddress)
|
||||
{
|
||||
//MailHelper mail = new MailHelper("第一次发送邮箱测试", "591410538@qq.com");
|
||||
//mail.Send();
|
||||
Message = message;
|
||||
UserMailAddress = userMailAddress;
|
||||
}
|
||||
public void Send()
|
||||
{
|
||||
MailMessage msg = null;
|
||||
//smtpClient.Credentials = new System.Net.NetworkCredential(mail.from.Send_Address.Address, mail.from.password);//设置发件人身份的票据
|
||||
//smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
|
||||
//smtpClient.Host = "smtp." + mail.from.Send_Address.Host;
|
||||
string account = App.Configuration["Mail:Account"];
|
||||
string passWord = App.Configuration["Mail:PassWord"];
|
||||
//var options = Options.Create(options: new MemoryCacheOptions());
|
||||
//IMemoryCache cache = new MemoryCache(options);
|
||||
SmtpClient smtpClient = new SmtpClient();
|
||||
smtpClient.EnableSsl = true;
|
||||
smtpClient.UseDefaultCredentials = false;
|
||||
smtpClient.Host = App.Configuration["Mail:Host"];
|
||||
smtpClient.Credentials = new System.Net.NetworkCredential(account, passWord);
|
||||
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
|
||||
|
||||
MailMessage mailMessage = new MailMessage();
|
||||
MailAddress fromAddr = new MailAddress(account);
|
||||
mailMessage.From = fromAddr;
|
||||
mailMessage.To.Add(UserMailAddress);
|
||||
mailMessage.Subject = App.Configuration["Mail:Subject"];
|
||||
mailMessage.BodyEncoding = Encoding.UTF8;
|
||||
mailMessage.IsBodyHtml = true;
|
||||
mailMessage.Priority = MailPriority.Low;
|
||||
mailMessage.Body = Message;
|
||||
try
|
||||
{
|
||||
smtpClient.Send(mailMessage);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.xg1100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,13 +43,15 @@ namespace Ewide.Core.Util
|
||||
/// <returns></returns>
|
||||
public static string Format(string key, int type)
|
||||
{
|
||||
string result = string.Empty; int length = key.Length / 64; for (int i = 0; i < length; i++)
|
||||
string result = string.Empty;
|
||||
int length = key.Length / 64;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int start = i * 64;
|
||||
result = result + key.Substring(start, 64) + "\r\n";
|
||||
}
|
||||
|
||||
result = result + key.Substring(length * 64); if (type == 1)
|
||||
result = result + key.Substring(length * 64);
|
||||
if (type == 1)
|
||||
{
|
||||
result = result.Insert(0, "-----BEGIN PUBLIC KEY-----\r\n");
|
||||
result += "\r\n-----END PUBLIC KEY-----";
|
||||
@@ -68,7 +70,6 @@ namespace Ewide.Core.Util
|
||||
/// <returns></returns>
|
||||
public static string RSAEncrypt(string content)
|
||||
{
|
||||
//string publickey = @"<RSAKeyValue><Modulus>tu98wMoo297l+juulU4a3Xx7c2SZ93f0gTPKohE0uz4o8jWN8zXnAAfhf6MMTlkgf+qIwaORLtBQohDcX6Xp02Qe7Cq2LujVR+YJHxy2uo8+KTc5Rj/d0OkTjeCozGaJQH0XrwUO7w+rDnyXzA52IvMZPnUV3KnOj1mPH0IhrOU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
|
||||
string publickey = App.Configuration["RSA:publickey"];
|
||||
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
||||
byte[] cipherbytes;
|
||||
@@ -84,7 +85,6 @@ namespace Ewide.Core.Util
|
||||
/// <returns></returns>
|
||||
public static string RSADecrypt(string content)
|
||||
{
|
||||
//string privatekey = @"<RSAKeyValue><Modulus>tu98wMoo297l+juulU4a3Xx7c2SZ93f0gTPKohE0uz4o8jWN8zXnAAfhf6MMTlkgf+qIwaORLtBQohDcX6Xp02Qe7Cq2LujVR+YJHxy2uo8+KTc5Rj/d0OkTjeCozGaJQH0XrwUO7w+rDnyXzA52IvMZPnUV3KnOj1mPH0IhrOU=</Modulus><Exponent>AQAB</Exponent><P>7yKLJO9dobe7pNW3ob+Vse8kvlA+PObDrZNqFxUTLyXoAeHDnwz3BjJ2EVUPNJHV5F1/KPLTvADIjDrdB1qcbw==</P><Q>w9ZK0SHBddtE91skFFS72YDmxzmXumSuUyREStVul9ke0oU2HjcZA915bmR0Zrh1RzO3y1w9zXVn+GdZGjyd6w==</Q><DP>ncA67E2fhcwv0+hMcD5zYOLyaT2EISbWFQ43ISz879BgwcUOCEFEP+lP69Uh57sAz9pBxWCS/uXBZoh6QJysrw==</DP><DQ>vbC8F4YS1g3l55Koh+jra+qnnyHyDeGn2XCvlazWys7MRC40FWBZIp1MGdnDxhu1vZoi1SAr3O90HfA9JmTAsQ==</DQ><InverseQ>00v2vMCcgXy78eMby7R6zfZzacVnVFO2WeyxYF7pjrXYYP+C4JSJkWpy6JGLWbgZrK8HAuRguJmdRi8K2KiYWg==</InverseQ><D>rV3nb9nmwQDMGMrI2GyN30uivygfFj0TdgK8Tb1aqPzu1yRT46M4yXmuhkTiW7nxp+iANGssIx5+3Ch4gRj+r6BgBPldWNErK95a2v2Ae1+EzfVf21ybguBYeUVnV9c8qwoodZSVOajZapOgoS6s5TEOxHWRcF22AiFuaD1Tl90=</D></RSAKeyValue>";
|
||||
string privatekey = App.Configuration["RSA:privatekey"];
|
||||
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
||||
byte[] cipherbytes;
|
||||
|
||||
@@ -90,7 +90,6 @@ namespace Ewide.Core.Util
|
||||
string fullName = string.Join('.', currentAssemblyName, name);
|
||||
return Assembly.Load(currentAssemblyName).CreateInstance(fullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入XML到磁盘
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user