views:

736

answers:

4

I am having this weired issue that CSV attachment sent via email using .NET SmtpClient appeared at the bottom of the email rather than attachment in Lotus Note. I just don’t know how to figure it out and I have no access to client computer makes debugging very hard. What are the possible steps I can take and possible gotchas I need to be aware of?

Code is as below:

var smtpClient = new SmtpClient
{
   Host = ConfigurationManager.AppSettings["smtpServer"],
   Port = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"])
};
var mailMessage = new MailMessage();
mailMessage.Attachments.Add(new Attachment(attachment, contentType)); 

//ContentType = "text/csv";
//attachment is the temp file disk path

Thanks.

A: 

In some mail clients there is an option to display attachments inline.

Most obvious test would be to send a .csv file attachment from other sources and see what the results are in the client having the issue.

Murph
I just sent a test email to the client using Outlook and the attachment showed up properly. I am pulling my hair atm.
Jeffrey C
A: 

Try not setting the content type and just setting the extension. Windows should be able to handle that if it has an extension and it may force it to handle it as an attachment instead of attempting to display it inline.

Make sure that your file that you are attaching has an extension.

Martin Murphy
+2  A: 

This is a bit of a reach, but you may want to set the content-disposition of the attachment.

var mailMessage = new MailMessage();
Attachment data = new Attachment(attachment, contentType); 
ContentDisposition disposition = data.ContentDisposition;
disposition.FileName = "message.csv";
mailMessage.Attachments.Add(data);

Adapted from: http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.contentdisposition.aspx

Ken Pespisa
this has worked for me beautifully. thanks!
Jeffrey C
A: 

Just for a test, try setting the content-type to something like "application/octet-stream" . For example (off the top of my head):

ContentType ct = new ContentType( "application/octet-stream" );
ct.Name = "message.csv";
data.ContentType = ct;

Cheers!

Dave

dave wanta