????????SmtpClient
???????????? ???????[ 2016/2/24 14:08:10 ] ??????????????? ???????
???????SmtpClient????Email?????????????ISmtpClient????SmtpClientWrapper???????????????ж?ISmtpClient????Mock???????FackeSmtpClient????nDumbster??Facke SMTP Server????????????????????????е??????????????Nuget????nDumbster????????????netDumbster??
????1.IEmailSender???
????public interface IEmailSender
????{
????void SendMail(string from?? string to?? string subject?? string body);
????}
????2.SMTPAdapter?????
public interfacepublic class SMTPAdapter : IEmailSender
{
public void SendMail(string from?? string to?? string subject?? string body)
{
var message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress(from);
message.To.Add(new MailAddress(to));
message.Subject = subject;
message.Body = body;
using (var smtpClient = new SmtpClient())
{
if (smtpClient.Host == null)
{
smtpClient.Host = "localhost";
}
smtpClient.Send(message);
}
}
}
????3.???nDumbster???????
public class SMTPAdapterTest
{
[Fact]
public void SendMailTest()
{
SimpleSmtpServer server = SimpleSmtpServer.Start(25);
IEmailSender sender = new SMTPAdapter();
sender.SendMail("sender@here.com"?? "receiver@there.com"?? "subject"?? "body");
Assert.Equal(1?? server.ReceivedEmailCount);
SmtpMessage mail = (SmtpMessage)server.ReceivedEmail[0];
Assert.Equal("sender@here.com"?? mail.Headers["From"]);
Assert.Equal("receiver@there.com"?? mail.Headers["To"]);
Assert.Equal("subject"?? mail.Headers["Subject"]);
Assert.Equal("body"?? mail.MessageParts[0].BodyData);
server.Stop();
}
}
???????н????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11