我必须将几个文件邮寄到一个电子邮件地址。这些文件需要具有 .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);
}
}
}
}