日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

hMailServer C#API

發(fā)布時間:2024/4/14 C# 78 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hMailServer C#API 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

公司企業(yè)郵箱需要使用hMailServer郵件服務(wù),因需求需要有用戶的添加、刪除、密碼重置接口,參考網(wǎng)上一些大神們的資料后,自己寫了一個C#的api類

參考網(wǎng)上的一些資料:?

源碼地址?https://github.com/hmailserver/hmailserver/ https://blog.csdn.net/oLinBSoft/article/details/65446059

https://blog.csdn.net/simeonzheng/article/details/7387522

1 public class hMailServerApi 2 { 3 public string domainStr = "";// 你的域名 4 public string admin = "Administrator"; 5 public string adminPassword = "xxx";// 你的管理員密碼 6 private dynamic getobDomain() 7 { 8 dynamic _app; 9 _app = Activator.CreateInstance(Type.GetTypeFromProgID("hMailServer.Application")); 10 _app.Authenticate(admin, adminPassword); 11 return _app.Domains.ItemByName(domainStr); ; 12 } 13 14 private dynamic getObAccount() 15 { 16 dynamic obDomain = getobDomain(); 17 var obAccounts = obDomain.Accounts; 18 return obAccounts; 19 } 20 /// <summary> 21 /// 用戶添加 22 /// </summary> 23 /// <param name="Address">郵箱賬號</param> 24 /// <param name="Password">密碼</param> 25 /// <param name="userName">用戶名</param> 26 /// <returns></returns> 27 public Result UserAdd(string Address, string Password, string userName) 28 { 29 Result result = new Result(); 30 try 31 { 32 var obAccounts = getObAccount(); 33 var obNewAccount = obAccounts.Add(); 34 obNewAccount.Address = Address; 35 obNewAccount.Password = Password; 36 obNewAccount.Active = 1; 37 obNewAccount.Maxsize = 500; 38 obNewAccount.Save(); 39 result.tag = true; 40 result.msg = "添加成功!"; 41 } 42 catch (Exception ex) 43 { 44 result.msg = "用戶:" + userName + "保存失敗!" + ex.Message + "\r\n"; 45 result.tag = false; 46 } 47 return result; 48 } 49 /// <summary> 50 /// 用戶刪除 51 /// </summary> 52 /// <param name="strUsername"></param> 53 /// <returns></returns> 54 public Result DeleteAccount(string strUsername) 55 { 56 Result result = new Result(); 57 try 58 { 59 dynamic obDomain = getobDomain(); 60 dynamic obAccounts = obDomain.Accounts; 61 dynamic obDelAccount = obAccounts.ItemByAddress(strUsername + "@" + domainStr); 62 obDelAccount.Delete(); 63 result.tag = true; 64 result.msg = "刪除成功!"; 65 } 66 catch (Exception ex) 67 { 68 result.msg = "刪除失敗:" + ex.Message + "\r\n"; 69 result.tag = false; 70 } 71 return result; 72 } 73 /// <summary> 74 /// 密碼重置 75 /// </summary> 76 /// <param name="strUsername"></param> 77 /// <param name="oldPassword"></param> 78 /// <param name="newPassword"></param> 79 /// <returns></returns> 80 public Result ResetPassword(string strUsername, string oldPassword, string newPassword) 81 { 82 Result result = new Result(); 83 try 84 { 85 dynamic obDomain = getobDomain(); 86 dynamic obAccounts = obDomain.Accounts; 87 dynamic obAccount = obAccounts.ItemByAddress(strUsername + "@" + domainStr); 88 string strPassword = obAccount.Password; 89 if (strPassword == string.Empty) 90 { 91 result.msg = "帳戶不正確或不存在 " + "\r\n"; 92 result.tag = false; 93 } 94 string strSALT = obAccount.Password.Substring(0, 6); 95 if (strSALT + GetSHA256(strSALT + oldPassword.Trim()) == obAccount.Password) 96 { 97 obAccount.Password = newPassword; 98 obAccount.Save(); 99 result.msg = "密碼重置成功! " + "\r\n"; 100 result.tag = true; 101 102 } 103 else 104 { 105 result.msg = "密碼輸入錯誤"; 106 result.tag = false; 107 } 108 } 109 catch (Exception ex) 110 { 111 result.msg = "密碼重置失敗:" + ex.Message + "\r\n"; 112 result.tag = false; 113 } 114 return result; 115 } 116 /// <summary> 117 /// 加密 118 /// </summary> 119 /// <param name="text"></param> 120 /// <returns></returns> 121 122 private string GetSHA256(string text) 123 { 124 byte[] hashValue; 125 byte[] message = Encoding.UTF8.GetBytes(text); 126 127 SHA256Managed hashString = new SHA256Managed(); 128 string hex = ""; 129 130 hashValue = hashString.ComputeHash(message); 131 foreach (byte x in hashValue) 132 { 133 hex += String.Format("{0:x2}", x); 134 } 135 return hex; 136 } 137 } 138 public class Result 139 { 140 public bool tag { get; set; } 141 public string msg { get; set; } 142 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/XiaoZone/p/9018257.html

總結(jié)

以上是生活随笔為你收集整理的hMailServer C#API的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。