Search code examples
c#sendmailmailmessage

C# send Email line break in body ignored when using command line


I am using C# MailMessage library to send email but I am facing issues when trying to call this .exe from command line with line breaks in it, it ignores the lines breaks. Can anyone help to find the root cause?


Solution

  • The answer depends on the terminal you are using. For example, with bash, you would specify your string using single quotations, preceded by $, for example:

    static void Main(string[] args)
    {
        foreach (var arg in args)
        {
            Console.WriteLine(arg);   
        }
    }
    
    > SomeApp.exe $'One\r\n\r\nTwo\r\n\r\n'
    One
    
    Two
    
    

    Unfortunately I'm not sure about other terminals/operation systems and dont have the ability to test them.