如何在ASP.Net应用程序中作为电子邮件发送的短信中包含换行符?

时间:2021-01-21 07:36:39

I have an ASP.Net Application that sends text messages to mobile phones. 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.

我有一个ASP.Net应用程序,可以向手机发送短信。它通过发送电子邮件来完成此操作。例如,如果您的电话号码是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

4 个解决方案

#1


3  

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); for each line

假设您在存储之前自己构建了主体,最简单的方法是在构建字符串和我们时使用stringbuilder .AppendLine(stuff);对于每一行

you can also use Environment.NewLine

您也可以使用Environment.NewLine

#2


6  

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.

这对我来说过去很有用,所以如果我是你,这是我第一次尝试。

#3


2  

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')

#4


2  

I believe for SMS a linefeed is sufficient. From C#, you can use (char)10.

我相信对于短信来说,换行就足够了。从C#开始,您可以使用(char)10。

#1


3  

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); for each line

假设您在存储之前自己构建了主体,最简单的方法是在构建字符串和我们时使用stringbuilder .AppendLine(stuff);对于每一行

you can also use Environment.NewLine

您也可以使用Environment.NewLine

#2


6  

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.

这对我来说过去很有用,所以如果我是你,这是我第一次尝试。

#3


2  

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')

#4


2  

I believe for SMS a linefeed is sufficient. From C#, you can use (char)10.

我相信对于短信来说,换行就足够了。从C#开始,您可以使用(char)10。