74 lines
1.5 KiB
Markdown
74 lines
1.5 KiB
Markdown
# Email server utilizzando IONOS email
|
|
|
|
utilizza account IONOS
|
|
|
|
é impostato sulla porta 3400
|
|
|
|
installa con
|
|
|
|
```sh
|
|
npm init -y
|
|
npm install body-parser dotenv express nodemailer
|
|
```
|
|
|
|
|
|
## Server semplice
|
|
|
|
inserisci indirizzo soggetto e testo
|
|
|
|
avvia con
|
|
|
|
node s1.js
|
|
|
|
puoi testarlo con
|
|
|
|
```sh
|
|
curl -X POST http://192.168.1.3:3400/send-email \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"to": "fabio.micheluz@gmail.com",
|
|
"subject": "Test dal server Express",
|
|
"text": "Questa è una email di prova inviata via curl"
|
|
}'
|
|
```
|
|
|
|
## Server completo
|
|
|
|
inserisci indirizzo soggetto testo html e allegati
|
|
|
|
tutti i parametri di configurazione sono nel file .env
|
|
|
|
avvialo con
|
|
|
|
node s2.js
|
|
|
|
esempio html con un pulsante che rimanda ad un link
|
|
|
|
```sh
|
|
curl -X POST http://192.168.1.3:3400/send-email \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"to": "fabio.micheluz@gmail.com",
|
|
"subject": "Email con testo, HTML e allegato",
|
|
"text": "Questa è la versione testuale della mail.",
|
|
"html": "<h1>Ciao Fabio!</h1><p>Questa è la versione HTML.</p><p><a href=\"https://google.com\" style=\"display:inline-block;padding:10px 20px;background:#007BFF;color:#fff;text-decoration:none;border-radius:5px;\">Esegui chiamata</a></p>",
|
|
"attachments": [
|
|
{
|
|
"filename": "prova.txt",
|
|
"path": "./prova.txt"
|
|
}
|
|
]
|
|
}'
|
|
```
|
|
|
|
|
|
come é fatto
|
|
|
|
```sh
|
|
├── body-parser@2.2.0
|
|
├── dotenv@17.2.3
|
|
├── express@5.1.0
|
|
└── nodemailer@7.0.10
|
|
```
|
|
|
|
|