Miss any of our Open RFC calls?Watch the recordings here! »

contactapi

1.0.2 • Public • Published

ContactAPI - NodeJS

Simple NodeJS package that allows you to make a contact request and send it by e-mail or put it in a database.

How to use

First you have to install the package using npm:


$ npm i contactapi

After that include the package to your NodeJS app and then you're able to create a ContactRequest-Object by using the method createContactRequest:

 
var  contactapi = require("../src/index");
 
  
 
var  contactRequest = contactapi.createContactRequest(mail, name, phone, message);
 
var  contactRequest = contactapi.createContactRequest("johndoe@gmail.com", "John Doe", "0123456789", "Hello World!");
 

If you don't want to use a object from the ContactRequest-Object (e.g. phone) simply replace it with null. However, please note that you aren't able to put it into the mail or into the database of course.

- First Opertunity

The following step is creating an object that send the data from the ContactRequest-Object as a mail. To do this, create a ContactRequestMailer-Object. The arguments for this are first the destination mail address, followed by the destination mail password, the SMTP host of your mail provider, and the SMTP port.

 
var  contactRequestMailer = contactapi.createContactRequestMailer(contactRequest, "yourmail@gmail.com", "password", "smtp.google.com", "587");
 

Now you can send the mail by calling the method sendMail with the arguments subjectFormat and messageFormat.

This first argument is the ContactRequest-Object we created.

The second argument is the title of the mail, that appears on the starting page of your email dashboard. You can use {name}, {mail} and {phone} for inserting the name, the mail or the phonenumber of the ContactRequest-Object into the title.

The third argument is the content of the mail, that appears when you click on the mail. You can use {name}, {mail}, {phone} or {message} for inserting the name, the mail, the phonenumber or the message of the ContactRequest-Object into the content.

 
contactRequestMailer.sendMail("Kontakt-Anfrage: {name}", "Name: {name}\nMail: {mail}\nPhone: {phone}\n\nNachricht:\n{message}");
 

- Second Opertunity

The following step is creating an object that send the data from the ContactRequest-Object to a database. To do this, create a ContactRequestMySQLPusher-Object. The arguments for this are first the host of your database, followed by the port, the username, the password and your database-name.

 
var  contactRequestMySQLPusher = contactapi.createContactRequestMySQLPusher("127.0.0.1", "3306", "admin", "yourpassword", "database");
 

Now you can push the data to the MySQL-DB by calling the method pushToMySQL. The only argument is the ContactRequest-Object we created.

 
contactRequestMySQLPusher.pushToMySQL(contactRequest);
 

You can get a list of all ContactRequests that were sent by calling the method getAllContactRequests.

 
contactRequestMySQLPusher.getAllContactRequests();
 

Credits

I used the nodemailer libary for sending the mail: https://github.com/nodemailer/nodemailer I used the mysql libary for push the data to MySQL: https://github.com/mysqljs/mysql

Keywords

Install

npm i contactapi

DownloadsWeekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

13 kB

Total Files

5

Last publish

Collaborators

  • avatar