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?
-
2possible duplicate of Sending emails with Javascriptartur grzesiak– artur grzesiak2014-12-03 21:37:47 +00:00Commented Dec 3, 2014 at 21:37
-
2You could probably wrap it into a directive. Here's one someone else put together.Eric McCormick– Eric McCormick2015-03-20 15:15:18 +00:00Commented Mar 20, 2015 at 15:15
-
3If you now have an answer to this question, you should enter the answer below (not as part of the question) and mark it as the answer, so it is immediately clear to other StackOverflow users this question has already been solved.Jason Parker– Jason Parker2015-04-27 15:14:01 +00:00Commented Apr 27, 2015 at 15:14
Add a comment
|
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");
Comments
use $window.location:
$window.location = "mailto:..."
1 Comment
garfunkel61
this doesn't open not needed new browser tab, while location.open() does. Seems better if you are sure that user need a external mail client to be opened.
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>
Comments
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.