我怎样才能prevent从邮件正文中显示的附件内容? [英] How can i prevent the attachment content from displaying in the body of the message?

查看:213
本文介绍了我怎样才能prevent从邮件正文中显示的附件内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发送一封电子邮件,一个附件一个asp.net C#应用程序。
附件是一个vCalendar文件。
这里的code:

I'm working on an asp.net c# application that sends an email with one attachment. The attachment is a vCalendar file. Here's the code:

            StringBuilder sbCalendar = new StringBuilder();
            DateTime dtStart = eventDate;
            DateTime dtEnd = eventDate;

            sbCalendar.AppendLine("METHOD: REQUEST");
            sbCalendar.AppendLine("BEGIN:VCALENDAR");
            sbCalendar.AppendLine("PRODID:-//DP//NET");
            sbCalendar.AppendLine("MIMEDIR//ENVERSION:1.0");
            sbCalendar.AppendLine("METHOD:REQUEST");
            sbCalendar.AppendLine("BEGIN:VEVENT");
            sbCalendar.AppendLine("DTSTAMP:" + dtStart.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
            sbCalendar.AppendLine("DTSTART:" + dtStart.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
            sbCalendar.AppendLine("DTEND:" + dtEnd.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
            sbCalendar.AppendLine("LOCATION:" + eventLocation);
            sbCalendar.AppendLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + eventBody);
            sbCalendar.AppendLine("SUMMARY:" + eventSubject);
            sbCalendar.AppendLine("PRIORITY:3");
            sbCalendar.AppendLine("UID:" + Guid.NewGuid().ToString());
            sbCalendar.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION:MAILTO:required@participant.foo");
            sbCalendar.AppendLine("ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:MAILTO:chair@foo.foo");
            sbCalendar.AppendLine("CLASS:PUBLIC");
            sbCalendar.AppendLine("ORGANIZER:MAILTO:organizer@foo.foo");
            sbCalendar.AppendLine("SEQUENCE:0");
            sbCalendar.AppendLine("STATUS:TENTATIVE");
            sbCalendar.AppendLine("END:VEVENT");
            sbCalendar.AppendLine("END:VCALENDAR");

            byte[] byteArray = Encoding.UTF8.GetBytes(sbCalendar.ToString());

            Stream contentStream = new MemoryStream(byteArray);

            SmtpClient smtp = new SmtpClient("localhost");

            MailMessage memo = new MailMessage();

            memo.IsBodyHtml = true;

            memo.From = new MailAddress("from@ddress.foo");

            foreach (string emailAddress in emailAddresses)
            {
                memo.To.Add(emailAddress);
            }

            memo.Body = messageBody;
            memo.Subject = messageSubject;

            Attachment attachment = new Attachment(contentStream, "termenLitigiu.ics", "text/calendar");
            attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            memo.Attachments.Add(attachment);
            smtp.Send(memo);

这工作和做什么是应该做的,它会发送一个工作vCalendar文件(由Outlook识别)。

This works and does what is supposed to do, it sends a working (recognized by outlook) vcalendar file.

的问题是,在邮件的主体,除了消息体参数的内容,附加文件的内容也会出现,是这样的:

The problem is that in the body of the mail, besides the contents of the messageBody parameter, the contents of the attached file also appear, something like this:

来源:发件人
发送时间:周二,2010年10月5日下午4时59分
要:someemail

From: sender Sent: Tuesday, October 05, 2010 4:59 PM To: someemail

下面内容的消息体

方法:REQUEST
  BEGIN:VCALENDAR
  PRODID: - // // DP NET
  MIMEDIR // ENVERSION:1.0
  方法:REQUEST
  BEGIN:VEVENT
  DTSTAMP:20101006T135934Z
  DTSTART:20101006T135934Z
  DTEND:20101006T135934Z
  位置:旅馆距离Minstead
  描述;编码=引用打印:我的第一次会议
  摘要:学习日历和日程安排
  优先级:3
  UID:721d9e3c-9010-47f5-9ad0-83c38cb0cbb7
  参会者; ROLE = REQ参与者; PARTSTAT = NEEDS-ACTION:MAILTO:someemail
  参会者; ROLE =椅子PARTSTAT =受理:至mailto:someemail
  类:public
  主办单位:MAILTO:someemail
  顺序:0
  状态:暂定
  END:VEVENT
  END:VCALENDAR

METHOD: REQUEST BEGIN:VCALENDAR PRODID:-//DP//NET MIMEDIR//ENVERSION:1.0 METHOD:REQUEST BEGIN:VEVENT DTSTAMP:20101006T135934Z DTSTART:20101006T135934Z DTEND:20101006T135934Z LOCATION:Minstead DESCRIPTION;ENCODING=QUOTED-PRINTABLE:My first meeting SUMMARY:Learning Calendaring and Scheduling PRIORITY:3 UID:721d9e3c-9010-47f5-9ad0-83c38cb0cbb7 ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION:MAILTO:someemail ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED:MAILTO:someemail CLASS:PUBLIC ORGANIZER:MAILTO:someemail SEQUENCE:0 STATUS:TENTATIVE END:VEVENT END:VCALENDAR

我想摆脱那种文字,并只显示我的消息体参数的内容与刚刚附加到邮件消息vCalendar文件。
我怎样才能做到这一点?这是一个前景问题和编码问题?

I want to get rid of that text, and display only the contents of my messageBody parameter and have the vCalendar file just attached to the mail message. How can i do this? Is this an outlook issue or a coding issue?

编辑:我只是在显示Microsoft Outlook中的邮件感兴趣。我看着到消息的来源(在Outlook中右键点击>查看源代码),我想摆脱的文字是在&LT;身体> &LT; /体<消息/ code >> html标记)

I'm only interested in displaying the message in Microsoft Outlook. I've looked into the source of the message (in Outlook right click > View Source) and the text i want to get rid of is within the <body></body> html tags of the message)

推荐答案

找到了解决办法:

http://msdn.microsoft.com/en-us/library/system.net.mime.dispositiontypenames.attachment.aspx

在我更换附件的构造文本/日历 MediaTypeNames.Application.Octet 并集在 DispositionType 附件,而不是内联这可能是的默认值。

In the constructor of the Attachment I replaced "text/calendar" with MediaTypeNames.Application.Octet and set the DispositionType to Attachment as opposed to Inline which was probably the default value.

            Attachment attachment = new Attachment(contentStream, "termenLitigiu.ics", MediaTypeNames.Application.Octet);
            attachment.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;

现在让我用含有什么应该的邮件正文和工作的.ics附件干净的邮件。

It now gives me a clean mail message with the body of the message containing what it should and a working .ics attachment.

这篇关于我怎样才能prevent从邮件正文中显示的附件内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆