C#MailTo与附件?

C#MailTo与附件?,第1张

C#MailTo与附件

mailto:不正式支持附件。我听说Outlook 2003将使用以下语法

<a href='mailto:[email protected]?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:file.txt"" '>

处理此问题的更好方法是使用System.Net.Mail.Attachment在服务器上发送邮件。

    public static void CreateMessageWithAttachment(string server)    {        // Specify the file to be attached and sent.        // This example assumes that a file named Data.xls exists in the        // current working directory.        string file = "data.xls";        // Create a message and set up the recipients.        MailMessage message = new MailMessage("[email protected]","[email protected]","Quarterly data report.","See the attached spreadsheet.");        // Create  the file attachment for this e-mail message.        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);        // Add time stamp information for the file.        ContentDisposition disposition = data.ContentDisposition;        disposition.CreationDate = System.IO.File.GetCreationTime(file);        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);        disposition.ReadDate = System.IO.File.GetLastAccessTime(file);        // Add the file attachment to this e-mail message.        message.Attachments.Add(data);        //Send the message.        SmtpClient client = new SmtpClient(server);        // Add credentials if the SMTP server requires them.        client.Credentials = CredentialCache.DefaultNetworkCredentials;        try {          client.Send(message);        }        catch (Exception ex) {          Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}",      ex.ToString() );}        data.Dispose();    }


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5567137.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存