【发布时间】:2012-03-24 14:33:01
【问题描述】:
public static void SendEmail(String from, String To, String Subject, String HTML, String AttachmentPath = null, String AttachmentName = null, MediaTypeNames AttachmentType = null)
{
....
// Add an attachment if required
if (AttachmentPath != null)
{
var ct = new ContentType(MediaTypeNames.Text.Plain);
using (var a = new Attachment(AttachmentPath, ct)
{
Name = AttachmentName,
NameEncoding = Encoding.UTF8,
TransferEncoding = TransferEncoding.Base64
})
{
mailMessage.Attachments.Add(a);
}
}
....
}
如您所见,MediaTypeNames AttachmentType 抛出错误:
'System.Net.Mime.MediaTypeNames': static types cannot be used as parameters
解决这个问题的最佳方法是什么?
【问题讨论】:
-
您可能希望使用“字符串”作为类型。 MediaTypeNames 包含许多类,每个类都有一些返回字符串的静态属性。