1

我必须将几个文件邮寄到一个电子邮件地址。这些文件需要具有 .tcx 文件扩展名。这些实际上是 xml 文件(Garmin 自行车日志)。

显然,当收件人收到电子邮件时,附件被命名为 xxxxx.tcx.xml。如何强制邮件程序不更改附件文件名?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.IO;

namespace stravamailer
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var files = Directory.GetFiles("E:\\JurgenS\\Downloads\\allrides");

            for (int i = 0; i < files.Length; i++)
            {
                MailMessage oMail = new MailMessage();
                oMail.Body = "";
                oMail.From = new MailAddress("jurgen@ccccc.be","Jurgen Stillaert");
                oMail.Subject = "";
                oMail.To.Add(new MailAddress("jurgen@cccc.be"));
                Attachment att = new Attachment(files[i]);
                att.Name = Path.GetFileName(files[i]);
                oMail.Attachments.Add(att);

                SmtpClient oSmtp = new SmtpClient("uit.telenet.be");
                oSmtp.Send(oMail);
            }
        }
    }
}
4

1 回答 1

0

Attachment 类与 MailMessage 类一起使用。所有消息都包含一个 Body,其中包含消息的内容。除了正文之外,您可能还想发送其他文件。这些作为附件发送并表示为附件实例。要将附件添加到邮件中,请将其添加到 MailMessage.Attachments 集合中。

附件内容可以是字符串、流或文件名。您可以使用任何附件构造函数来指定附件中的内容。

附件的 MIME Con​​tent-Type 标头信息由 ContentType 属性表示。Content-Type 标头指定媒体类型和子类型以及任何相关参数。使用 ContentType 获取与附件关联的实例。

MIME Con​​tent-Disposition 标头由 ContentDisposition 属性表示。Content-Disposition 标头指定附件的表示和文件时间戳。仅当附件是文件时才发送 Content-Disposition 标头。使用 ContentDisposition 属性获取与附件关联的实例。

MIME Con​​tent-Transfer-Encoding 标头由 TransferEncoding 属性表示。

这里是源

您的解决方案在此 MSDN 链接中。你应该试试 MIME Con​​tent-Type。

于 2012-05-04T18:21:19.100 回答