在C#中格式化纯文本电子邮件 [英] Formatting a plain text e-mail in C#

查看:173
本文介绍了在C#中格式化纯文本电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用纯文本在电子邮件中打印一张表格。
我有以下代码:

I am trying to print a table inside an e-mail using plain text. I have the following code:

string body = string.Format("{0,-30}{1,-30}{2,-50}{3,-40}",
                                   "Col1", "Col2", "Col2", "Col4");

body += string.Format("{0,-30}{1,-30}{2,-50}{3,-40}",
                                value1, value2, value3, value4);

Microsoft.Office.Interop.Outlook.ApplicationClass myOutlookApplication = null;
myOutlookApplication = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.MailItem myNewMail = 
    (Microsoft.Office.Interop.Outlook.MailItem)myOutlookApplication.CreateItem( 
      Microsoft.Office.Interop.Outlook.OlItemType.olMailItem );            

myNewMail.To = recipient;
myNewMail.Subject = subject;
myNewMail.Body = body;
myNewMail.BodyFormat = OlBodyFormat.olFormatPlain;            

myNewMail.Send();

我遇到的问题是身体的文字不排队。它也似乎将文本包裹在邮件中。任何人都可以告诉我我在这里做错了什么?

The problem I have is that the text for the body does not line up. It also seems to wrap the text inside the mail. Can anyone tell me what I may be doing wrong here?

推荐答案

创建(或实际模仿)文本仅在以下情况下有效:

Creating (or actually imitating the behaviour of) a table in plain text only works well when:


  1. 表中的值与列的宽度完全相同。这是您(程序员)在文本太短或文字过长时,通过拖放文本而处理的东西。

  1. The values in your tables are exactly the same width as the widht of the column. This is something you (the programmer) should take care of by trailing the text with spaces when the text is too short or cutting of the text if is too long.

接收文本的用户正在使用等宽字体( http://en.wikipedia.org / wiki / Monospaced_font )来查看表格。不幸的是,如果你发送电子邮件中的表格是不可控制的...

The user that is receiving the text is using a monospace font (http://en.wikipedia.org/wiki/Monospaced_font) to view the table. And that is unfortunately beyond your control if you send the table in an e-mail message...

这篇关于在C#中格式化纯文本电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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