C#winform发送邮件不添加附件就会结束进程,添加就能发送成功。
发布网友
发布时间:2022-05-10 16:41
我来回答
共2个回答
热心网友
时间:2023-10-16 18:12
能贴下源码么。
这个是可以发送附件,抄送,Html的源码。
SmtpClient smtp = new SmtpClient(account.SmtpSvr);
smtp.Credentials = new NetworkCredential(account.UserName, account.Password);
MailMessage msg = new MailMessage();
MailAddress mailFrom = new MailAddress(account.UserName);
string[] tos = to.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in tos)
{
MailAddress mailTo = new MailAddress(item);
msg.To.Add(mailTo);
}
string[] ccs = cc.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in ccs)
{
MailAddress mailCC = new MailAddress(item);
msg.CC.Add(mailCC);
}
msg.From = mailFrom;
msg.Subject = subject;
msg.SubjectEncoding = Encoding.UTF8;
msg.Body = content;
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = !chkIsHtml.Checked;
foreach (string item in lstAttachments.Items)
{
msg.Attachments.Add(new Attachment(item));
}
smtp.Send(msg);
热心网友
时间:2023-10-16 18:13
可能在添加附件那里有个判断 只有分析源码了