Search code examples
angulartypescriptcpanel

How to send email from server/cPanel with angular?


I have an angular application with a contact form. On user submitting the contact form I want to automatically send an email to myself with the users inputs.

Is it possible to send the email from the server or cPanel using only angular? How?

If not; what is the simplest way to achieve this?


Solution

  • ANSWER:

    No, it is not possible to "send the email from the server or cPanel using only angular". Angular is limited to front-end only.

    THE SOLUTION:

    Implement a server-side application (in my case node js) on the shared server allowing me to write server-side code.

    SENDING DATA FROM ANGULAR APPLICATION TO NODE JS:

    Import HttpClientModule to angulars app.module.ts

    Import HttpClient to the typescript file I wanted to send data from allowing me to "POST" the users contact data to the newly implemented node js application.

    this.http.post('/send', f.value)
      .subscribe((res) => {
        console.log(res);
    });
    

    SENDING THE EMAIL:

    Upon the node js application receiving the data I used nodemailer and some stock standard code to create and send an email using SMTP protocol.

    RESULTS:

    The code for both the angular and node js apps will be posted shortly on GitHub and the finished product can be found at JamesEllisDev.com.