[英]How do I include a newline in a text message sent as email from an ASP.Net application?
I have an ASP.Net Application that sends text messages to mobile phones. 我有一个ASP.Net应用程序,可以向手机发送短信。 It does this by sending an email.
它是通过发送电子邮件来完成的。 For instance, if your phone number is 555-555-5555 and your wireless carrier is Verizon, you can send an email to 5555555555@vtext.com and it will show up as a text message.
例如,如果您的电话号码是555-555-5555且您的无线运营商是Verizon,您可以发送电子邮件至5555555555@vtext.com,它将显示为短信。
I want to be able to include a newline in the body of the message. 我希望能够在邮件正文中包含换行符。 How do I do this?
我该怎么做呢? Also please note that my ASP.Net program gets the message from a database (MS SQL Server) so what I really need to know is what characters to include in the message body when I store it in my database.
另请注意,我的ASP.Net程序从数据库(MS SQL Server)获取消息,所以我真正需要知道的是当我将它存储在数据库中时要包含在消息体中的字符。
I already tried \\n but it just showed up in the text message as \\n 我已经尝试了\\ n但它只是在短信中显示为\\ n
You need to use Environment.NewLine
instead of \\n
您需要使用
Environment.NewLine
而不是\\n
That has worked for me in the past, so it's the first thing I'd try if I were you. 这对我来说过去很有用,所以如果我是你,这是我尝试的第一件事。
Assuming you are building the bodies yourself prior to storage, the easiest way is to just use stringbuilder when building your strings and us .AppendLine(stuff);
假设您在存储之前自己构建了主体,最简单的方法是在构建字符串和我们时使用
.AppendLine(stuff);
for each line 对于每一行
you can also use Environment.NewLine 您也可以使用Environment.NewLine
I am not sure if you need just a line feed, or a carriage return/line feed, so try using CHAR
, like this: 我不确定您是否只需要换行符或回车符/换行符,因此请尝试使用
CHAR
,如下所示:
insert into Messages
(PhoneNo, Message)
values
('123-555-1234', 'line 1' + char(13) + char(10) + 'line 2')
I believe for SMS a linefeed is sufficient. 我相信对于短信来说,换行就足够了。 From C#, you can use
(char)10
. 从C#开始,您可以使用
(char)10
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.