I have to mail several files to an e-mail address. The files needs to have .tcx file extension. These are in fact xml files (Garmin bicycle logs).
Apparently when the receiver gets the email, the attachement is named xxxxx.tcx.xml. How can I force the mailer not to change the attachment file name?
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);
}
}
}
}
Here is the source
Your solution is in this MSDN link. you should try MIME Content-Type.