&sectl2024-09-24

[Send Emails From The Command Line Using Swaks]

  1. install
$ sudo apt-get install swaks
``

2. Sending emails using Swaks

1. Plaintext Email: This command sends a basic email with a subject and a plaintext body.

swaks
--from alexlai@hc4Noble.yushei.net
--to alexlai@h2Jammy.yushei.net,rai.sousuke@gmail.com,rai.sousuke@mac.com
--server hc4Noble.yushei.net
--port 25
--auth plain
--auth-user 'alexlai'
--auth-password 'alex1765'
--header 'Subject: Test email'
--body "This is a test email. Current time: $(date)"


swaks
--from alexlai@hc4Noble.yushei.net
--to alexlai@h2Jammy.yushei.net,rai.sousuke@gmail.com,rai.sousuke@mac.com
--server h2Jammy.yushei.net
--port 25
--auth plain
--auth-user 'alexlai'
--auth-password 'alex1765'
--header 'Subject: Test email'
--body "This is a test email. Current time: $(date)"

swaks \
        --from alexlai@hc4Noble.yushei.net \
        --to alexlai@hc4Noble.yushei.net \
        --server hc4Noble.yushei.net \
        --port 25 \
        --auth plain \
        --tls \
        --auth-user 'alexlai' \
        --auth-password 'alex1765' \
        --header 'Subject: Test email' \
        --body "This is a test email. Current time: $(date)"
swaks --to hc4Noble.yushei.net --from alexlai@hc4Noble.yushei.net --server localhost \
  --port 25 --auth-user alexlai --auth-password alex1765
  1. HTML Email: To send an HTML email, you need to specify the content type and provide the HTML content in the body.
swaks \
        --from sender@example.com \
        --to recipient@example.com \
        --server send.ahasend.com \
        --port 587 \
        --auth plain \
        --tls \
        --auth-user 'YOUR_SMTP_USERNAME' \
        --auth-password 'YOUR_SMTP_PASSWORD' \
        --header 'Subject: Test email' \
        --body "<html><body><h1>This is a Heading</h1><p>This is a paragraph.</p></body></html>" \
        --add-header "Content-Type: text/html"
  1. Attachments: Sending an email with attachments involves adding the --attach option. Here's how you can send an email with both plaintext and an attachment.
swaks \
        --from sender@example.com \
        --to recipient@example.com \
        --server send.ahasend.com \
        --port 587 \
        --auth plain \
        --tls \
        --auth-user 'YOUR_SMTP_USERNAME' \
        --auth-password 'YOUR_SMTP_PASSWORD' \
        --header 'Subject: Test email' \
        --body "This email contains an attachment." \
        --attach /path/to/file.txt