Question

I am a beginner in MVC. I want to develop an action method in MVC which fires Mailto:?body=body goes here.&subject=test subject and so the default mail client will automatically populate the email for the user. Right now I have List<String> which contain mailto: urls.

Please, if you have any experience or demo code it will be helpful to me. Thanks in advance.

Was it helpful?

Solution 2

My ActionMethod

[HttpPost]
public JsonResult emailTemplate()
{
    List<String> str = new List<String>();
    str.Add("Mailto:?body=Hello1&subject=test subject1");
    str.Add("Mailto:?body=Hello2&subject=test subject2");
    return Json(str);
}

JavaScript Function in view

function SendMailClicked() {

        $.ajax({
            type: "POST",
            url: "/Home/emailTemplate",
            //data: "{'ReviewComponentIds':'1,2,3'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                jQuery.each(response, function () {

                    window.location.href = this + '\n';
                });
            },
            failure: function (errMsg) {
                alert('failure');
            }
        });

    }

OTHER TIPS

try this :

window.location.href = "mailto:address@dmail.com";

with body

window.location.href = "mailto:address@dmail.com?body=yourBody";

Event with jquery

$('button').on('click', function(){
    window.location.href = "mailto:address@dmail.com?body=yourBody";
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top