C#的MailMessage发送邮件如何设置Content-Disposition和Content-Type,请高手指教 5
C#的MailMessage发送邮件如何设置Content-Disposition和Content-Type,请高手指教...
C#的MailMessage发送邮件如何设置Content-Disposition和Content-Type,请高手指教
展开
1个回答
展开全部
public static void SendEmail(string fromname,
string senderemail,
string senderserver,
string senderuser,
string senderpassword,
string emails,
string subject,
string txt,
string[] files, string encoding)
{
using (MailMessage mailmess = new MailMessage())
{
mailmess.From = new MailAddress(senderemail, fromname, Encoding.GetEncoding(encoding));
mailmess.To.Clear();
foreach (string destemail in emails.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (destemail.Contains(":"))
{
string[] mailInfo = destemail.Split(':');
mailmess.To.Add(new MailAddress(mailInfo[0].Trim(), mailInfo[1].Trim()));
}
else
{
mailmess.To.Add(destemail);
}
}
mailmess.Subject = subject;
mailmess.SubjectEncoding = Encoding.GetEncoding(encoding);
mailmess.Body = txt;
mailmess.BodyEncoding = Encoding.GetEncoding(encoding);
foreach (string path in files)
{
if (!string.IsNullOrEmpty(path))
mailmess.Attachments.Add(new Attachment(path));
}
SmtpClient client = new SmtpClient(senderserver);
client.Credentials = new NetworkCredential(senderuser, senderpassword);
try
{
client.Send(mailmess);
}
finally
{
}
}
}
string senderemail,
string senderserver,
string senderuser,
string senderpassword,
string emails,
string subject,
string txt,
string[] files, string encoding)
{
using (MailMessage mailmess = new MailMessage())
{
mailmess.From = new MailAddress(senderemail, fromname, Encoding.GetEncoding(encoding));
mailmess.To.Clear();
foreach (string destemail in emails.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (destemail.Contains(":"))
{
string[] mailInfo = destemail.Split(':');
mailmess.To.Add(new MailAddress(mailInfo[0].Trim(), mailInfo[1].Trim()));
}
else
{
mailmess.To.Add(destemail);
}
}
mailmess.Subject = subject;
mailmess.SubjectEncoding = Encoding.GetEncoding(encoding);
mailmess.Body = txt;
mailmess.BodyEncoding = Encoding.GetEncoding(encoding);
foreach (string path in files)
{
if (!string.IsNullOrEmpty(path))
mailmess.Attachments.Add(new Attachment(path));
}
SmtpClient client = new SmtpClient(senderserver);
client.Credentials = new NetworkCredential(senderuser, senderpassword);
try
{
client.Send(mailmess);
}
finally
{
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询