Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke mailto in AngularJS controller

I'm implementing a simple email feedback feature in angular app. The mail has predefined mail subject and content template. The angular controller need bring up client email client (like invoke "mailto:[email protected]") and fulfill predefined subject, content template. Any body know how to implement it?

like image 486
duckegg Avatar asked Oct 21 '13 11:10

duckegg


4 Answers

Inject $window and use $window.open() method.

Inside controller define...

$scope.sendMail = function(emailId,subject,message){
    $window.open("mailto:"+ emailId + "?subject=" + subject+"&body="+message,"_self");
};

and call it like...

$scope.sendMail("[email protected]","Mail Subject","Mail Body Message");
like image 154
Ankit Pundhir Avatar answered Oct 12 '22 18:10

Ankit Pundhir


use $window.location:

$window.location = "mailto:..."
like image 34
zhekaus Avatar answered Oct 12 '22 18:10

zhekaus


This should open new tab for Google mail or email client, depending on users settings.

In Angular JS: Concatenate string in controller like so:

$scope.mailLink = "mailto:" + $scope.emailId + "?subject=" + $scope.Subject + '&body=' + $scope.bodyText;

html

<a ng-href="{{mailLink}}" target="_blank">Send</a>
like image 32
Uliana Pavelko Avatar answered Oct 12 '22 18:10

Uliana Pavelko


location.href works too!

$scope.email = function(item){
    location.href= 'mailto:' + $scope.allemails (array) + '?subject=Subject you want';
}

Note: If you have an array in $scope.allemails, and you will use method .join(', ') - thunderbringer email client will not recognize this as a collection of emails and it will add a new line of 'To:' to every email from that array.

like image 24
Nicolae Maties Avatar answered Oct 12 '22 20:10

Nicolae Maties