locked
Problems with webmail RRS feed

  • Question

  • User2117521848 posted

    Hello,

    I am trying to send an email via webmail. The body of the email is created as follows:

    initemail = "Hello, My name is Joe and I would like to invite you to join my new site." + Environment.NewLine;
    initemail = initemail + Environment.NewLine + "Just click on the following link to join my site and get started !!" + Environment.NewLine + Environment.NewLine;

    (followed by some other text)
    try {
          WebMail.Send(
          to: singleaddress,
          subject: "Invitation To My Site",
          body: initemail
          );                  
        } catch (System.Web.Security.MembershipCreateUserException e) {
                  ModelState.AddFormError(e.Message);
        }
    The email sends fine and arrives at the specified mailbox, but the new lines (Environment.NewLine) cannot be seen in the
    received email - just contiguous text.

    I thought this might be an encoding issue (like maybe I should be encoding as UTF-8) but Webmail does not seem to accept
    an encoding argument.

    Help ????

    Thanks
    Rich





    Sunday, June 12, 2016 3:56 PM

Answers

  • User895691971 posted

    The email is not in html

    Well, sadly, that is not being set in the source code that you are using. Also, most of the email clients use HTML based formatting for the emails to render the message that was sent to them which means it is recommended (and preferred) to have your email as an HTML document instead of plain-text document. Either use the following, 

    WebMail.Send(
        to: singleaddress,
        subject: "Invitation To My Site",
        body: initemail,
        isBodyHtml: false
    );

    Otherwise, you can use the HTML document to create the email message body. 

    initemail = "<p>Hello, My name is Joe and I would like to invite you to join my new site. <br /><br />";
    initemail += "Just click on the following link to join my site and get started !!<br /></p>";

    This would work with the similar code that you are using at the moment. Notice that I have used paragraph elements to add the browser-based margins to the content. Instead of adding extra white-area to the email body, it would be recommended to leave that to the email client itself. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 13, 2016 10:08 AM

All replies

  • User475983607 posted

    The Environment.NewLine inserts  control/linefeed characters which will work if the email is viewed in plain text.  If the emails is in HTML then you'll need to use the HTML break tag; <br />.

    Sunday, June 12, 2016 4:16 PM
  • User2117521848 posted

    Thanks you for the reply. The email is not in html

    Sunday, June 12, 2016 9:29 PM
  • User753101303 posted

    Hi,

    According to https://msdn.microsoft.com/en-us/library/hh414138(v=vs.111).aspx it uses HTML by default. What if you try to add isBodyHtml:false to define this optional parameter to false if you don't want to use HTML?

    Sunday, June 12, 2016 9:53 PM
  • User895691971 posted

    The email is not in html

    Well, sadly, that is not being set in the source code that you are using. Also, most of the email clients use HTML based formatting for the emails to render the message that was sent to them which means it is recommended (and preferred) to have your email as an HTML document instead of plain-text document. Either use the following, 

    WebMail.Send(
        to: singleaddress,
        subject: "Invitation To My Site",
        body: initemail,
        isBodyHtml: false
    );

    Otherwise, you can use the HTML document to create the email message body. 

    initemail = "<p>Hello, My name is Joe and I would like to invite you to join my new site. <br /><br />";
    initemail += "Just click on the following link to join my site and get started !!<br /></p>";

    This would work with the similar code that you are using at the moment. Notice that I have used paragraph elements to add the browser-based margins to the content. Instead of adding extra white-area to the email body, it would be recommended to leave that to the email client itself. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 13, 2016 10:08 AM