locked
WebMail.Send additionalHeaders RRS feed

  • Question

  • User560738307 posted

    I'm trying to send an email from my application, no problem there, but I want to add an additional header (reply to).

                // Send email
                List<String> additionalHeaders = new List<String>();
                additionalHeaders.Add("Reply-To: test@test.com");
                List<String> filesToAttach = new List<String>();
                WebMail.Send("peter.de.keer@gmail.com","Reserveringsformulier van frans formulier",body,WebMail.From,"",filesToAttach,true,additionalHeaders);
                //WebMail.Send(to, subject, body [, from] [, cc] [, filesToAttach] [, isBodyHtml]   [, additionalHeaders])


    I have two questions:

    1. Do I need to add all parameters to the Send function? Since the additionalHeaders is last, do I need to add from, cc, filesToAttach, isBodyHtml?
    2. The code above doesn't give me errors, but the reply to is not added to the message. I'm doing something wrong here.


    I have also a general remark to the webmatrix team: The documentation at http://www.asp.net/webmatrix/tutorials/asp-net-web-pages-api-reference is not enough! First I need to find out what type each parameter must be and then I need to find out how I can create them. I'm a true beginner, and really would like some code examples online!

    I know you are going to refer to the sample applications, but this information must be online and more easely available (I don't want to close my application in webmatrix, create a website I don't want on my pc, find out how to do something, close the application, open mine again, change something, see that is doesn't work, close my app, open the sample app, see how it's really done, open my application, try to change the code but forget wat the answer was, etc... ) I don't really want to work like that. If the sample apps were available online, we could all link to certain parts of it to clarify the workings of some helpers.

    Thursday, November 11, 2010 8:10 AM

Answers

  • User-346176016 posted

    If you want  spec of classes and APIs use the object browser in Visual web dev , or a program called reflector.

    Regarding your mail function issue , use the parameter names :

    @{
        WebMail.Send("webmail@free.fr",
    "subject",
    "this is the body", 
    additionalHeaders: new List<string>() { "blop", "blap" }
    );
    }



    Regards Mark Prades 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 11, 2010 1:20 PM
  • User-821857111 posted

    What you see at http://www.asp.net/webmatrix/tutorials/asp-net-web-pages-api-reference is nothing more than release notes at the moment. It's not worthy of the term "documentation". WebMatrix is still in Beta, and the documentation won't be released until the product is. Given that the proposed publication date for Laurence Moroney's book is Feb 15th next year, I suspect you will see a full release round about then.

    I don't want to close my application in webmatrix, create a website I don't want on my pc, find out how to do something, close the application, open mine again, change something, see that is doesn't work, close my app, open the sample app, see how it's really done, open my application, try to change the code but forget wat the answer was, etc...

    You can have WebMatrix open more than once on your PC. Just switch between the two.

    The Send method takes these arguments:

    string to,
    string subject,
    string body,
    [Optional, DefaultParameterValue(null)] string from,
    [Optional, DefaultParameterValue(null)] string cc,
    [Optional, DefaultParameterValue(null)] IEnumerable<string> filesToAttach,
    [Optional, DefaultParameterValue(true)] bool isBodyHtml,
    [Optional, DefaultParameterValue(null)] IEnumerable<string> additionalHeaders

    Anything marked Optional is not required, but if you only want to pass values to some of them, you must name the parameter. For example, let's say you are only interested in specifying that the body should be HTML. The method call would look like this:

    WebMail.Send(toAddress, subject, body, isBodyHtml: true)

    Notice how the name of the isBodyHtml parameter is added, followed by a colon, and then followed by the value. If you wanted to also specify the from name, it would look like this:

    WebMail.Send(toAddress, subject, body, isBodyHtml: true, from: "Some String")

    Again, the parameter name is used followed by the value. It doesn't even have to be in the same order as they appear in the method definition, so long as all required parameters are added first.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 12, 2010 3:48 AM

All replies

  • User-346176016 posted

    If you want  spec of classes and APIs use the object browser in Visual web dev , or a program called reflector.

    Regarding your mail function issue , use the parameter names :

    @{
        WebMail.Send("webmail@free.fr",
    "subject",
    "this is the body", 
    additionalHeaders: new List<string>() { "blop", "blap" }
    );
    }



    Regards Mark Prades 


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 11, 2010 1:20 PM
  • User-821857111 posted

    What you see at http://www.asp.net/webmatrix/tutorials/asp-net-web-pages-api-reference is nothing more than release notes at the moment. It's not worthy of the term "documentation". WebMatrix is still in Beta, and the documentation won't be released until the product is. Given that the proposed publication date for Laurence Moroney's book is Feb 15th next year, I suspect you will see a full release round about then.

    I don't want to close my application in webmatrix, create a website I don't want on my pc, find out how to do something, close the application, open mine again, change something, see that is doesn't work, close my app, open the sample app, see how it's really done, open my application, try to change the code but forget wat the answer was, etc...

    You can have WebMatrix open more than once on your PC. Just switch between the two.

    The Send method takes these arguments:

    string to,
    string subject,
    string body,
    [Optional, DefaultParameterValue(null)] string from,
    [Optional, DefaultParameterValue(null)] string cc,
    [Optional, DefaultParameterValue(null)] IEnumerable<string> filesToAttach,
    [Optional, DefaultParameterValue(true)] bool isBodyHtml,
    [Optional, DefaultParameterValue(null)] IEnumerable<string> additionalHeaders

    Anything marked Optional is not required, but if you only want to pass values to some of them, you must name the parameter. For example, let's say you are only interested in specifying that the body should be HTML. The method call would look like this:

    WebMail.Send(toAddress, subject, body, isBodyHtml: true)

    Notice how the name of the isBodyHtml parameter is added, followed by a colon, and then followed by the value. If you wanted to also specify the from name, it would look like this:

    WebMail.Send(toAddress, subject, body, isBodyHtml: true, from: "Some String")

    Again, the parameter name is used followed by the value. It doesn't even have to be in the same order as they appear in the method definition, so long as all required parameters are added first.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 12, 2010 3:48 AM
  • User560738307 posted

    It seems to be a bug; I added it to the webmatrix feedback:

    https://connect.microsoft.com/webmatrix/feedback/details/636327/cannot-add-additionalheader-reply-to-in-webmail-send

    Sunday, January 16, 2011 7:20 AM