Send Emails by console with sendmail

This case was tested in Canaima and Ubuntu

1- We install SendEmail:

apt-get install sendemail

2- We install the following packages necessary for its correct operation with GMail:

apt-get install libnet-ssleay-perl

apt-get install libio-socket-ssl-perl

Now we are ready to send our emails. To use our GMail account, we type in the console:

sendemail -f nombrecuenta@gmail.com -t cuentadestino@isp.com -s smtp.gmail.com:587 -u \
"Asunto" -m "Cuerpo del mensaje" -a archivoadjunto -v -xu nombrecuenta -xp clavecuenta -o tls=yes

Where:

«accountname@gmail.com»Is our GMail account

«accountdestino@isp.com»Is the account to which we want to send our mail (if we want to send to several recipients we just have to leave a blank space between the email addresses)

In "Subject»Goes exactly the subject of the mail (if it goes between quotes) and in«Message body»What we want to write (also in quotes)

The option -a goes if we want to send an attachment

«accountname»Is the name of our GMail account without the @

«password account»Is our password to our GMail account

Now now a small script made in bash to send a mailing list in txt

#!/bin/bash
# -*- ENCODING: UTF-8 -*-
i=0
while read line
do i=$(($i+1));
sendemail -f correo@gmail.com -t $line -s smtp.gmail.com:587 -u "TITULO" -m "CUERPO DEL MENSAJE" -v -xu nombredeusuariosinelaroba -xp contraseña -o tls=yes
done < "/home/direccion/correos"
echo "Final line count is: $i";


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Fabio.Felio said

    CURRENTLY most of the YOUNG people only pay attention to the FACEBOOK account and there they reach the OTHERS folder. CALL CENTERS are legal and the most screwed up. The CELLULAR and the FACEBOOK account are the targets of neo spammers. Good tutoring, something basic but it will help some ...

    1.    Fabio.Felio said

      I recommend using php + mysql + cron on some free server using a proxy like people.

      With this 3-column database.
      ID (int, autoincrement, primarykey) | email (tinytext) | sent (boolean)

      You simply have to get an email from the database to which we have not sent you yet.

      We send you the email, we can use the corresponding WP object to send email if we are in wordpress in a plugin or the mail function of php.

      We write down the sending to that email in the database and we leave

      Running it every 3 minutes with a scheduled task using cron. In order not to overload the servers, nor to alert gmail or hotmail. This is the most important…

      Or, a javascript script for the browser using greasemonkey / tampermonkey that runs in your browser on the gmail page with your email open. They can also use a mysql database, if they have an http server with mysql and php running they can make a request with "ajax" inside the script and receive the email. Then when everything is correct send a request to the local server informing him of the shipment so that he can write down.

      In short, the possibilities are limitless. The only thing, which is not practical from what I clarified in my first message, and it is illegal.

      1.    Fabio.Felio said

        Either the legality depends on this:

        http: / / en. wikipedia. org / wiki / CAN-SPAM_Act_of_2003

  2.   eliotime3000 said

    Fine, but that is much more useful if you want to chain hoaxes and thus satisfy the lammer spirit that we have within.

    Anyway, thanks for the tip.

  3.   arianfornaris said

    Hello, very interesting article. I am developing a program that sends certain logs to an email account but there are thousands of emails that must be sent, because the said log is quite old and extensive. As I connect little to the internet, it takes a long time. So I have the following doubts:

    1- Is Sendmail faster than python's smtp module?
    2- How to use the same session (I don't know if session is the most appropriate word) to send several emails?
    3- Is there a way for sendmail to report progress?
    4- I have no idea if smtp implements some type of data compression, so that the volume of data to be sent is drastically reduced since the logs are plain text.

    regards
    Arian fornaris

  4.   Orelvis said

    All very interesting but how can I protect my mail server so that it does not accept to send emails if you do not have a user on the server or if it is not sent from a local address.

    Thank you.

  5.   Paul said

    Hello, the script is very good, but when I run it, I get this error, you could help me solve it

  6.   Paul said

    Aug 20 15:27:29 pablo-hp-envy-15-notebook-pc sendemail [2841]: DEBUG => Connecting to smtp@gmail.com: 587
    Aug 20 15:27:32 pablo-hp-envy-15-notebook-pc sendemail [2841]: ERROR => Connection attempt to smtp@gmail.com: 587 failed: IO :: Socket :: INET6: getaddrinfo: System error
    Aug 20 15:27:32 pablo-hp-envy-15-notebook-pc sendemail [2841]: HINT => Try specifying a different mail relay with the -s option.
    final line count is: 1

  7.   nestor said

    Thank you is what I was looking for.

  8.   veraine said

    it will work with another pop3 mail

  9.   Mark Alexis said

    How do I configure it to be used with hotmail?