Asp.net 将PDF附加到邮件并使用C在用户计算机中使用默认邮件客户端打开#
我的要求是将PDF文件附加到电子邮件,并使用C#代码使用默认邮件客户端(如outlook或windows live mail)打开 这应该通过用户配置为默认的默认电子邮件客户端来完成 我把MAPI检查到这个。然而,我仍然找不到合适的代码来做这件事 这是我使用的代码Asp.net 将PDF附加到邮件并使用C在用户计算机中使用默认邮件客户端打开#,asp.net,sendmail,email-attachments,Asp.net,Sendmail,Email Attachments,我的要求是将PDF文件附加到电子邮件,并使用C#代码使用默认邮件客户端(如outlook或windows live mail)打开 这应该通过用户配置为默认的默认电子邮件客户端来完成 我把MAPI检查到这个。然而,我仍然找不到合适的代码来做这件事 这是我使用的代码 MailMessage message = new MailMessage(); Attachment data = new Attachment(file, MediaTypeNames.Application.O
MailMessage message = new MailMessage();
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastWriteTime(file);
message.Attachments.Add(data);
请尝试以下代码:
List<System.Net.Mail.Attachment> lstAttachment = new List<System.Net.Mail.Attachment>();
if (File.Exists(AttachmentFilePath))//AttachmentFilePath is path of attachment
{
PDF = new System.Net.Mail.Attachment(AttachmentFilePath);
PDF.Name = "DEMO_PDF.pdf";
lstAttachment.Add(PDF);
objMailer.Attachments = lstAttachment;//objMailer is mail client object.
}
List lstatchment=新列表();
如果(File.Exists(AttachmentFilePath))//AttachmentFilePath是附件的路径
{
PDF=新系统.Net.Mail.Attachment(AttachmentFilePath);
PDF.Name=“DEMO_PDF.PDF”;
附件.Add(PDF);
objMailer.Attachments=lstatchment;//objMailer是邮件客户端对象。
}
将不会打开默认电子邮件客户端此问题已在此处回答