c# generated csv file sent via email embedded to bottom of email in lotus note

好久不见. 提交于 2019-12-08 02:51:53

问题


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.


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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;


来源:https://stackoverflow.com/questions/891598/c-sharp-generated-csv-file-sent-via-email-embedded-to-bottom-of-email-in-lotus-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!