Curs Javascript

- Trimitere Email cu Atasament

Pentru a trimite un email cu Node.js, poti folosi modulul Nodemailer, usureaza trimiterea email-urilor de pe calculatorul tau.
Iti trebuie un cont la un furnizor de servicii email, spre exemplu Gmail care este gratuit cu limita de maximum 500 email-uri pe zi.

Trimitere email cu modulul Nodemailer

1. Mai intai, instaleaza modulul Nodemailer cu NPM; in interfata command prompt:
npm install --save nodemailer
- Dupa ce ai descarcat modulul Nodemailer, poti include modulul in orice aplicatie:
const nodemailer = require('nodemailer');
2. Acum, pentru a trimite email-uri de pe server cu Node.js, scrie un cod care foloseste numele si parola inregistrate la furnizorul de servicii email.
Aici aveti un script simplu pentru a trimite email-uri cu Gmail.
- Copiaza si salveaza urmatorul cod intr-un fisier "sendmail.js" in directorul cu proiectul tau Node.js:
const nodemailer = require('nodemailer');

const trans = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'youremail@gmail.com',
    pass: 'password'
  }
});

let mail_op ={
  from: 'youremail@gmail.com',
  to: 'myfriend@yahoo.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

trans.sendMail(mail_op, (err, info)=>{
  if(err){
    console.log(err);
  } else {
    console.log('Email sent: ' + info.response);
  }
});
- Pentru a trimite mesaje cu tag-uri html, inlocuieste in "mail_op" proprietatea "text" cu "html":
let mail_op ={
  from: 'youremail@gmail.com',
  to: 'myfriend@yahoo.com',
  subject: 'Sending Email using Node.js',
  html: '<h1>Welcome</h1><p>That was easy!</p>'
}
Asta e tot! Initiaza fisierul "sendmail.js" in interfata command line si serverul tau ar trebui sa trimita email-ul prin GMail.
node test/sendmail.js

Folosire SMTP

Poti folosi de asemenea si serverul SMTP pentru a trimite email-ul:
const trans = nodemailer.createTransport({
  host: 'smtp.gmail.com', // hostname
  port: 465, // secure:true for port 465, secure:false for port 587
  secure: true, // port for secure SMTP
  auth: {
    user: 'youremail@gmail.com',
    pass: 'password'
  }
});
Daca iti returneaza o eroare ca aceasta:
Invalid login: username and password not accepted
...
responseCode: 535,
command: 'AUTH PLAIN'
Logeazate la: //www.google.com/settings/security/lesssecureapps si activati "Access for less secure apps".

Trimiterea email la mai multe adrese

Pentru a trimite un email la mai multe adrese, adaugati adresele de email, separate prin virgula, in proprietatea "to" a obiectului cu optiuni: "mail_op".
let mail_op ={
  from: 'youremail@gmail.com',
  to: 'myfriend@yahoo.com, myotherfriend@yahoo.com',
  subject: 'Sending Email using Node.js',
  html: '<h3>The life is Happiness.</h3>'
}
- De asemenea, puteti adauga proprietatile "cc" și "bcc" cu o lista de adrese de email la care sa trimiteti, si care vor aparea in campurile Cc, respectiv Bcc.

Trimitere email cu atasament

Pentru a adauga unul sau mai multe atasamente email-ului tau, adauga proprietatea "attachments" in obiectul cu mesajul transmis, care va contine cate un obiect pt. fieare atasament.
Puteti adauga un sir utf-8 ca atasament, un stream, un fisier local sau chiar si un fisier de la o adresa URL. Pentru mai multe detalii, vedeti documentatia de la:
Nodemailer - Atasamente.

- Aici aveti un exemplu de cod pentru trimitere email cu Nodemailer prin GMail, contine doua atasamente: un fisier local (file.zip) si un fisier PDF de la o adresa URL:
var nodemailer = require('nodemailer');

var trans = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'youremail@gmail.com',
    pass: 'password'
  }
});

let mail_op ={
  from: 'youremail@gmail.com',
  to: 'myfriend@yahoo.com',
  subject: 'You are Blessed with Miracles',
  html: '<h1>Welcome</h1><p>Have a Happy Life with everyone and with yourself.</p>',
  attachments: [
    { //using a local file
      path: __dirname+'/file.zip'
    },
    {   //using URL as an attachment
      filename: 'art_of_believing.pdf',
      path: 'https://coursesweb.net/blog/dwl/prayer_the_art_of_believing.pdf'
    },
  ]
};

trans.sendMail(mail_op, (err, info)=>{
  if(err){
    console.log(err);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

Un Test simplu in fiecare zi

HTML
CSS
JavaScript
PHP-MySQL
Engleza
Spaniola
Ce tag adauga imagine in pagina web?
<div> <img> <span>
<img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Care din aceste coduri CSS afiseaza textul inclinat?
font-style: italic; text-decoration: underline; font-weight: 500;
#id {
  font-style: italic;
}
Clic pe functia jQuery care ascunde animat un element HTML.
click() hide() show()
$(document).ready(function() {
  $(".a_class").click(function(){ $(this).hide("slow"); });
});
Clic pe functia definita corect in PHP.
fname function() {} function fname() {} function $fname() {};
function fname($a, $b) {
  echo $a * $b;
}
Indicati forma pentru Prezent Perfect Continuu a verbului "to walk" (a merge).
have walked have been walking be walking
I have been walking for 5 hours.
- Merg pe jos de 5 ore.
Indicati Trecutul Nedefinit pentru verbul "ser" (a fi) la forma Yo.
será sería fui
Yo fui entrenador.
- Am fost antrenor.
Node.js - Trimitere Email cu Nodemailer

Last accessed pages

  1. Ser - Estar 2 (3296)
  2. Gramatica limbii spaniole. Indrumator si prezentare generala (66985)
  3. Adverbele in limba engleza - Adverbs (32510)
  4. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (268696)
  5. Accentul si Pronuntia (27427)

Popular pages this month

  1. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (1359)
  2. Exercitii engleza - English Tests and exercises - Grammar (1085)
  3. Prezentul simplu si continuu - Present Tense Simple and Continuous (1079)
  4. Gramatica limbii engleze - Prezentare Generala (1030)
  5. Prezentul simplu - Exercitii si teste incepatori (887)