/// <summary> /// 连接消息队列并从队列中接收消息 /// </summary> private static void ReceiveMessage() { string path = (".\\Private$\\MailBack"); if (!MessageQueue.Exists(path)) { MessageQueue.Create(path); } while (true) { //连接到本地队列 MessageQueue myQueue = new MessageQueue(path); myQueue.Formatter = new BinaryMessageFormatter(); SendMailCommon sendMail = new SendMailCommon(); try { //从队列中接收消息 Message myMessage = myQueue.Receive(); MailBodyAndSetting context = (MailBodyAndSetting)myMessage.Body; //获取消息的内容 sendMail.SendMail(context.Body, context.Settings); } catch (Exception e) { //Console.WriteLine(e.Message); } } }
public void ConvertToString() { List <string> strlist = new List <string>(); strlist.Add(""); strlist.Add(""); strlist.Add(""); string[] ret = SendMailCommon.ConvertToString(strlist); Assert.AreEqual(0, ret.Length); strlist.Clear(); strlist.Add("sdfdf"); strlist.Add(""); strlist.Add("sfsfs"); ret = SendMailCommon.ConvertToString(strlist); Assert.AreEqual(2, ret.Length); }