简体   繁体   English

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

[英]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.

相关问题 如何在页面重定向后发布消息以确认已发送的消息(C#/ ASP.Net) - How do I post a message to confirm a sent message after a page redirect (C#/ASP.Net) 在ASP.NET中发送的电子邮件上显示确认消息 - Display confirmation message on email sent in ASP.NET 使用c#asp.net显示从网站发送的电子邮件内的图像 - Display image inside email message sent from website using c# asp.net 如何通过电子邮件发送的链接登录asp.net应用程序 - How do I Login to asp.net application through a link send via email 我将如何通过传递电子邮件和密码从 Asp.Net MVC Web 应用程序登录到 slack - How i will log into slack from Asp.Net MVC web application by passing email and password ASP.NET无法从smtp发送电子邮件 - ASP.NET cannot sent email from smtp 如何从Mutliple CheckBoxList选择检索输出并将其放置在ASP.Net的电子邮件文本文件中 - How Can I Retrieve the Output from Mutliple CheckBoxList Selections & Place in Email Text File in ASP.Net 如何向asp.net中的dropfolder发送电子邮件? - How do I send email to a dropfolder in asp.net? ASP.Net-如何包含另一个项目的嵌入式JavaScript文件? - ASP.Net - How do I include an embedded JavaScript file from another project? 如何测试asp.net电子邮件正在发送 - How to test asp.net email is being sent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM