This question already has answers here:
mailto link multiple body lines
(4 answers)
Closed 8 years ago.
I dont know whats happening here but I cant join two strings together with a newline between them. I use the following code in my Windows Store App to open the email client and prefill an email:
String recipient = "me#here.com";
String Bodymsg = "Line One" + Environment.NewLine + "Line Two";
String SubLine = "Report Fault";
String BodyText = "mailto:?to=" + recipient + "&subject=" + SubLine + "&body=" + Bodymsg;
var mailto = new Uri(BodyText);
await Windows.System.Launcher.LaunchUriAsync(mailto);
This works fine but the body comes out like this.
Line OneLineTwo
What I want to get is
Line One
Line Two
I have tried using "/r/n" and "/n" instead of Environment.NewLine but it gives the same effect. Any ideas where I'm going wrong?
The newline character is \n and not /n, have you tried:
String Bodymsg = "Line One\nLine Two";
Without seeing more of your code and how you're using the email, I'd say it might be formatted in HTML. Try concatenating the two strings with a <BR>.
Related
I'm having two problems with reading my .csv file with streamreader. What I'm trying to do is get the values, put them into variables which I'll be using later on, inputting the values into a browser via Selenium.
Here's my code (the Console.Writeline at the end is just for debugging):
string[] read;
char[] seperators = { ';' };
StreamReader sr = new StreamReader(#"C:\filename.csv", Encoding.Default, true);
string data = sr.ReadLine();
while((data = sr.ReadLine()) != null)
{
read = data.Split(seperators);
string cpr = read[0];
string ydelsesKode = read[1];
string startDato = read[3];
string stopDato = read[4];
string leverandoer = read[5];
string leverandoerAdd = read[6];
Console.WriteLine(cpr + " " + ydelsesKode + " " + startDato + " " + stopDato + " " + leverandoer + " " + leverandoerAdd);
}
The code in and of itself works just fine - but I have two problems:
The file has values in Danish, which means I get åøæ, but they're showing up as '?' in console. In notepad those characters look fine.
Blank values also show up as '?'. Is there any way I can turn them into a blank space so Selenium won't get "confused"?
Sample output:
1372 1.1 01-10-2013 01-10-2013 Bakkev?nget - dagcenter ?
Bakkev?nget should be Bakkevænget and the final '?' should be blank (or rather, a bank space).
"Fixed" it by going with tab delimited unicode .txt file instead of .csv. For some reason my version of excel doesn't have the option to save in unicode .csv...
Don't quite understand the problem of "rolling my own" parser, but maybe someday someone will take the time to explain it to me better. Still new-ish at this c# stuff...
This question already has answers here:
Replace "\\" with "\" in a string in C#
(9 answers)
Closed 7 years ago.
string url = #"..\" + row.Field<String>(1).Replace("photo",#"photo\");
url.Replace(#"\\", #"\");
i´m trying to put a single backslash but c# put that as \\
did you try something like the following?
string url = #"..\" + row.Field(1).Replace("photo",#"photo\");
url = url.Replace(#"\", #"\");
i,e add "url = " assigning.
I'm trying to send emails that contains special characters like á, é, ó, í, ú, etc. My code looks like this:
try
{
Mail message = Mail.GetInstance();
foreach (Users u in users)
{
message.AddBcc(u.Email);
}
message.From = new MailAddress(Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailFrom"), Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailFromName"));
message.Subject = Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailSubject");
message.Html = "<meta charset=\"UTF-8\"/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText1") +
" " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
var transport = SMTP.GetInstance(new NetworkCredential(
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailLogin"),
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailPass")));
transport.Deliver(message);
isEmailSent = true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message + " \n " + ex.InnerException + " \n " + ex.StackTrace);
isEmailSent = false;
}
I tried to specify the charset in the Html I'm sending but it doesn't work, instead of sending this San Jerónimo Amanal, this is what is being sent San Jerónimo Amanal.
How can I send it in the correct encoding? Any help will be appreciated.
EDIT
I tried this two approches:
message.Html = "<meta charset=\"UTF-8\"/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText1") +
" " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
And this:
message.Html = Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting
("emailText1") + " " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
But the email is still being sent with the wrong encoding.
EDIT 2
I tried the answer on this question Converting Unicode strings to escaped ascii string, more especifically, I tried the method EncodeNonAsciiCharacters but I got this in the email San Jer\u00c3\u00b3nimo Amanal. Did I take the wrong approach in this one?
Well it took some time, but at least I found a way to send the email without the special characters, I had to normalize the string I got with Normalization Form Compatibility Decomposition, which is done through the String class' Normalize method like this:
string normalizedString = InString.Normalize(NormalizationForm.FormKD);
With this, quoting from wikipedia:
characters are decomposed by compatibility, and multiple combining
characters are arranged in a specific order.
Meaning if there's also a character whose compability is represented by two characters, then it will be replace by said characters. With characters like é, it will be replaced by e.
wassup guys im new to C# coding and i did a search but couldn't find exactly what im looking for. So i have a couple of text-boxes which holds string elements and integers
what i want to do is when these boxes are filled in i want to send a summary of the email to client/customer but the format is whats getting me.
(first, one) are strings equaling different text-boxes
my code is:
emailCompseTask.Body = first + one + Enviroment.NewLine +
second + two + Enviroment.NewLine
and so on problem is which i send thru email it shows something like this:
computer service25.00
instead of:
computer service 25.00
is there a way to add spacing to make this more presentable? or even a better way perhaps thanks in advance guys
try this :
emailCompseTask.Body = first + one + " "+ second + two ;
body takes as HTML input, check here for more spacing option.
I'm a bit confused, but you just want to add some spacing in the output? Just throw some spaces in there like you would another variable.
first + " " + one + Environment.NewLine
+ second + " " + two + Environment.NewLine;
You can use a table
string tableRow = #"<tr>
<td>{0}</td>
<td>{1}</td>
</tr>";
string htmlTable = #"<table>
{0}
</table>";
string rows = "";
// Can do this in a loop
rows += string.Format(tableRow, first, one);
rows += string.Format(tableRow, first, one);
emailComseTask.Body = string.Format(htmlTable, rows);
strEmail =
"Hi All,"
+ "<br>"
+ "The User "
+ lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString()
+ " has been created on "
+ DateTime.Now.ToShortDateString()
+ "."
I am writing C# code to generate an email whenever a new user has been created. I need the body of the mail in a mail format like
hi,
The user "xxx" has been created on "todaysdate".
Thanks,
yyyy
so I need to insert linebreaks and bold for some characters. How might I achieve this?
If this is a plain text email (which it looks like it is), use \r\n for new lines.
strEmail = string.Concat("Hi All,\r\n\r\nThe User",
lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString(),
"has been created on ",
DateTime.Now.ToShortDateString(),
".\r\n\r\nThanks, yyyy");
Strickly speaking this should be Environment.NewLine to support different platforms, but I doubt this is a concern.
Set
yourMessage.IsBodyHtml = true
Msdn-Reference can be found here.
In order to form, you can use like below:
Response.Write("Hi,<br/><br/>The user.......");