I have an ASP.NET Web Form which was timing out when sending over 1800 emails whose addresses were being obtained from a DB. So I’m attempting to send the emails from a console application instead – I will access the DB there.
I need to pass the email subject line and body text as parameters to the ProcessStartInfo method but need guidance with the syntax. Can anyone help? Specifically, if I concatenate the subject and body vars and separate them with a space, will that suffice or will spaces in the vars cause problems?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Both the email subject and body should already contain spaces so you need to obey the same rules as if you were calling the program from the command line and enclose in " the arguments that contain spaces, otherwise each space in the subject will delimit a new argument.
Another special case is if the subject and body already contain the " character so you also need to account for that.
I think this should do the trick:
string subject = "Hello World!";
string body = @"This has "" quotes """;
string arguments = string.Format(
@"""{0}"" ""{1}""",
subject.Replace(@"""", @""""""),
body.Replace(@"""", @""""""));
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0