83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using YLErp.MailKit;
|
|
|
|
namespace YLErp.Forms
|
|
{
|
|
public partial class FormMail : Form
|
|
{
|
|
public FormMail()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int port = 25;
|
|
var strPort = tbPort.Text.Trim();
|
|
if (!string.IsNullOrEmpty(tbPort.Text) && !int.TryParse(tbPort.Text, out port))
|
|
{
|
|
MessageBox.Show("解析端口失败:" + tbPort.Text);
|
|
return;
|
|
}
|
|
|
|
var smtpConfig = new SmtpConfig
|
|
{
|
|
EnableSsl = chkSSL.Checked,
|
|
From = tbFrom.Text.Trim(),
|
|
Password = tbPassword.Text,
|
|
Port = port,
|
|
Receipt = chkReceipt.Checked,
|
|
Server = tbServer.Text.Trim(),
|
|
UserName = tbUserName.Text.Trim(),
|
|
ZipAttach = false
|
|
};
|
|
MailSender.Send(smtpConfig, new MailSendingOption
|
|
{
|
|
MailTo = new[] { tbMailTo.Text.Trim() },
|
|
Subject = "测试邮件发送",
|
|
Body = "测试邮件发送",
|
|
IsBodyHtml = false,
|
|
FilesToAttach = null,
|
|
CC = null
|
|
});
|
|
MessageBox.Show("邮件发送成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("邮件发送失败:\r\n" + ex.ToString());
|
|
LogFactory.GetLogger("邮件发送").Error("邮件发送失败", ex);
|
|
}
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
var str = textBox1.Text;
|
|
|
|
if (string.IsNullOrWhiteSpace(str))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SmtpConfig sc;
|
|
|
|
var index = str.IndexOf("[|]");
|
|
if (index > 0)
|
|
{
|
|
str = str.Substring(0, index);
|
|
}
|
|
var nv = YieldChain.Helpers.UrlHelper.ParseQueryString(str, true);
|
|
|
|
chkSSL.Checked = nv[nameof(sc.EnableSsl)]?.ToLowerInvariant() == "true";
|
|
chkReceipt.Checked = nv[nameof(sc.Receipt)]?.ToLowerInvariant() == "true";
|
|
|
|
tbServer.Text = nv[nameof(sc.Server)];
|
|
tbPort.Text = nv[nameof(sc.Port)];
|
|
|
|
tbFrom.Text = nv[nameof(sc.From)];
|
|
tbUserName.Text = nv[nameof(sc.UserName)];
|
|
tbPassword.Text = nv[nameof(sc.Password)];
|
|
}
|
|
}
|
|
}
|