Using mutt now

This commit is contained in:
Dryusdan 2020-05-14 16:48:24 +02:00
parent dc349520fd
commit a575dc64c1
3 changed files with 55 additions and 10 deletions

View File

@ -1,7 +1,4 @@
GHOST_USER=
GHOST_PASSWORD=
GHOST_WEBSITE=
MAIL_USER=
MAIL_PASSWORD=
MAIL_HOST=
MAIL_PORT=
MAIL_FROM="Me <me@domain.tld>"

View File

@ -9,9 +9,25 @@ So, I wrote this script (improveable) for sending newsletters.
## Prerequisite
- s-nail
- mutt
- curl
## Prepare mutt
Create `~/.muttrc` and add under into this file
```
set my_pass='S3Cr3t'
set my_user='me@domain.fr'
set realname = 'Dryusdan.fr'
set from = 'me@domain.fr'
set use_from = yes
set smtp_url=smtps://$my_user:$my_pass@smtp.domain.fr
set ssl_force_tls = yes
set ssl_starttls = yes
```
## How to work
First time, copy .env.sample to .env and complete this file.
@ -19,4 +35,4 @@ First time, copy .env.sample to .env and complete this file.
Get id of post (admin>post>mypost in url the last value (like 5b7522322114)).
Then, write in a terminal : `./ghost.sh postid` where postid is the value get before.
This script send with s-nail, one by one, with 30 secondes to slip (to esquivate rate limit).
This script send with mutt, one by one, with 30 secondes to slip (to esquivate rate limit).

40
ghost.sh Normal file → Executable file
View File

@ -46,20 +46,52 @@ curl -c ghost-cookie.txt -d username=${GHOST_USER} -d password=${GHOST_PASSWORD}
info "Getting HTML and subject"
# Use the session cookie to create a post
SUBJECT=$(curl -s -b ghost-cookie.txt -H "Origin: https://${GHOST_WEBSITE}" "https://${GHOST_WEBSITE}/ghost/api/v3/admin/email_preview/posts/${1}/" | jq --raw-output '.email_previews[].subject')
SUBJECT="Nouvel article sur mon blog : $(curl -s -b ghost-cookie.txt -H "Origin: https://${GHOST_WEBSITE}" "https://${GHOST_WEBSITE}/ghost/api/v3/admin/email_preview/posts/${1}/" | jq --raw-output '.email_previews[].subject')"
HTML=$(curl -s -b ghost-cookie.txt -H "Origin: https://${GHOST_WEBSITE}" "https://${GHOST_WEBSITE}/ghost/api/v3/admin/email_preview/posts/${1}/" | jq --raw-output '.email_previews[].html')
PLAINTEXT=$(curl -s -b ghost-cookie.txt -H "Origin: https://${GHOST_WEBSITE}" "https://${GHOST_WEBSITE}/ghost/api/v3/admin/email_preview/posts/${1}/" | jq --raw-output '.email_previews[].plaintext')
info "Getting email"
for member in $(curl -s -b ghost-cookie.txt -H "Origin: https://${GHOST_WEBSITE}" "https://${GHOST_WEBSITE}/ghost/api/v3/admin/members/?limit=all" | jq --raw-output ".members[] | @base64")
do
email=$(echo ${member} | base64 --decode | jq --raw-output '.email')
#email=$(echo ${member} | base64 --decode | jq --raw-output '.email')
email="contact@dryusdan.fr"
uuid=$(echo ${member} | base64 --decode | jq --raw-output '.uuid')
HTML=$(echo ${HTML} | sed "s/preview=1/uuid=${uuid}/g")
if [ $(echo ${member} | base64 --decode | jq --raw-output '.subscribed') == true ]
then
info "send email to ${email}"
HTML=$(echo ${HTML} | sed "s/preview=1/uuid=${uuid}/g")
echo "${HTML}" | s-nail -v -r "${MAIL_USER}" -s "Nouvel article sur mon blog : ${SUBJECT}" -C "Content-type: text/html;" -S smtp="${MAIL_HOST}:${MAIL_PORT}" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="${MAIL_USER}" -S smtp-auth-password="${MAIL_PASSWORD}" "${email}"
boundary="$(openssl rand -hex 24)"
content_type="content_type='multipart/alternative; boundary=${boundary}'"
##
cat << END > newmail.eml
From: ${MAIL_FROM}
To: ${email}
#Date: $(date)
Subject: ${SUBJECT}
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="${boundary}"
--$boundary
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
${PLAINTEXT}
--$boundary
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
${HTML}
--$boundary--
END
##
info "Sending mail"
echo "" | mutt -H newmail.eml
sleep 30
rm newmail.eml
else
warning "No email send ${email}"
fi