Nikola Brežnjak blog - Tackling software development with a dose of humor
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Home
Daily Thoughts
Ionic
Stack Overflow
Books
About me
  • Home
  • Daily Thoughts
  • Ionic
  • Stack Overflow
  • Books
  • About me
Nikola Brežnjak blog - Tackling software development with a dose of humor
Ionic

How to send an email in Ionic framework application?

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

As you may know, I’m really into Ionic framework lately and am helping out on StackOverflow with the knowledge I gained so far with the framework. I’m in the top All time answerers list.

I answered this question by user varun:

I have a simple page with 3 textbox and a button like this.

<input type="text" ng-model="name" required >
<input type="text" ng-model="city" required >
<input type="text" ng-model="country" required >

<button class="button button-block button-royal ExploreBtn" ng-click="sendMail();">
Send mail               
</button>

Help me , How to send mail with value in first text-field as subject and other two as body in angular js/ionic.

My answer was rather elaborate:

So, basically the comments to your question are correct – you can’t do this purely in JavaScript, you need to use a backend service for it.

Now, what you would do in your sendMail function is call the service by using Angulars’ $httpservice. You can learn more about $http service from the official documentation.

The call would, for example look like this:

$http({
    method: 'POST',
    url: 'http://your.server.com/sendmail.php',
    data: { mailTo: '[email protected]', msg: 'hello!' }
}).then(function successCallback(response) {
    alert("msg sent!");
}, function errorCallback(response) {
    alert("error with sending a msg");
});

Here you have two important parts:

  • url – where is your service (which will finally send the email) located
  • data – what are you sending to this service endpoint

In my example I’ve put the service url to be sendmail.php which, in end, would be written in PHP. I have to stress out that your backend service can be written in any server-side language you’re familiar with (if you’ll research this topic further make sure you read about the RESTful services).

For the sake of this example, the PHP script (unsecured and just for reference) which uses the mail function to send an email would look something like this:

<?php

$to = $_POST["emailTo"];
$msg = $_POST["msg"];

mail($to, "Some test subject", $msg);

?>

Hope this helps clear the confusion.

https://twitter.com/HitmanHR/status/679287774650998785

Miscellaneou$

57th SQL/DEV user group meeting about refactoring and transpilers

I attended our local Microsoft community user group meeting which was about refactoring and transpilers. It’s full proper title (on Croatian) was 57. sastanak SQL/DEV UG Čakovec-Varaždin.

This was 57th meeting in a row, and the presenter Nikola Begedin had two awesome topics (with few notes I took):

Principi i konvencije u refaktoriranju koda (Principles and conventions in code refactoring)

57devug_1

There are typical problems in every code with typical fixes for each of these problems. So, it’s useful to know them in order to be able to detect them early in the code and fix them before they introduce technical debt.

Few of the principles:

  • extract temp to query
  • tell, don’t ask
  • data clump
  • decoupling

You should look to refactor

  • God objects
  • high churn code
  • bugs – “bugs like company”. If a bug appeared at the same function, then refactor it because it’s obviously too cumbersome and the bug will inevitably manifest itself again

Few of the recommended books:

  • Clean Code: A Handbook of Agile Software Craftsmanship
  • Refactoring: Improving the Design of Existing Code
  • Growing Object-Oriented Software, Guided by Tests

Korištenje transpilera (using transpilers)

57devug_2

Transpiler is a source to source compiler. What that means is that it’s basically a tool which translates from one language to another.

Transpilers allow us to write modern JavaScript code, to work with modules, use advanced language features (await, async, arrow functions, …), etc.

Some options that we have today are:

  • Babel
  • Google Traceur
  • Browserify
  • RequireJS

Visual studio 2015 supports Gulp task running via Task Runner Explorer.

The point is that we don’t need these but since sooner or later more and more browsers will support these functions and you can use them already today, I don’t see any reason why not to use all the benefits that they offer.

https://twitter.com/HitmanHR/status/679276361492598784

Recent posts

  • Discipline is also a talent
  • Play for the fun of it
  • The importance of failing
  • A fresh start
  • Perseverance

Categories

  • Android (3)
  • Books (114)
    • Programming (22)
  • CodeProject (35)
  • Daily Thoughts (77)
  • Go (3)
  • iOS (5)
  • JavaScript (127)
    • Angular (4)
    • Angular 2 (3)
    • Ionic (61)
    • Ionic2 (2)
    • Ionic3 (8)
    • MEAN (3)
    • NodeJS (27)
    • Phaser (1)
    • React (1)
    • Three.js (1)
    • Vue.js (2)
  • Leadership (1)
  • Meetups (8)
  • Miscellaneou$ (77)
    • Breaking News (8)
    • CodeSchool (2)
    • Hacker Games (3)
    • Pluralsight (7)
    • Projects (2)
    • Sublime Text (2)
  • PHP (6)
  • Quick tips (40)
  • Servers (8)
    • Heroku (1)
    • Linux (3)
  • Stack Overflow (81)
  • Unity3D (9)
  • Windows (8)
    • C# (2)
    • WPF (3)
  • Wordpress (2)

"There's no short-term solution for a long-term result." ~ Greg Plitt

"Everything around you that you call life was made up by people that were no smarter than you." ~ S. Jobs

"Hard work beats talent when talent doesn't work hard." ~ Tim Notke

© since 2016 - Nikola Brežnjak