How to fire mailto urls from action method

13,773

Solution 1

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');
            }
        });

    }

Solution 2

try this :

window.location.href = "mailto:[email protected]";

with body

window.location.href = "mailto:[email protected]?body=yourBody";

Event with jquery

$('button').on('click', function(){
    window.location.href = "mailto:[email protected]?body=yourBody";
});
Share:
13,773
Suraj
Author by

Suraj

10 years professional experiences on enterprise level cloud based web applications and IoT domain. Expert knowledge on Cloud Computing Azure and IoT (Internet Of Things) domain. Expert knowledge on automated solution for enterprise level data integration from various data sources to expedite the overall Software Development Life Cycle. Most recently worked on an Enterprise Application product built on ASP.Net MVC 5 hosted on Azure and Amazon S3, C#, LINQ, RESTful Web API using Nodejs and Expressjs, JQuery, angular 7, CSS, SQL Server, MongoDB. Used TFS, JIRA and Github for version control and source code management. Experience in Design of Database, Data Models. Experience in n-tier architecture, design patterns and OOP methodologies(.NET Objects, N-Tier using .NET class), SQL server, user interface, software tools, enterprise architecture, third party software integration and implementation Experience in developing test cases for Unit Testing, Integration Testing and System Testing

Updated on June 13, 2022

Comments

  • Suraj
    Suraj almost 2 years

    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.

  • Suraj
    Suraj almost 11 years
    Thank you Bastien for your reply. I know this stuff. I want this is from action method. In my scenario I am processing some logic over server and genrate mailto:.. links and these links i need to fire from action method itself. @Bastien D
  • Suraj
    Suraj almost 11 years
    But how to call this from action method window.location.href = "mailto:[email protected]"; ??? and mail list is multiple
  • Tombeau
    Tombeau almost 11 years
    if i want a whole div content instead of specific string then how can i do that?