Author Topic: command line mail sender !  (Read 715 times)

foobar

  • Member
  • **
  • Posts: 308
  • Kudos: 0
    • http://www.fuckmicrosoft.com
command line mail sender !
« on: 12 July 2002, 23:45 »
I got pine working now (http://forum.fuckmicrosoft.com/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=5&t=000493), but it's still not what i was looking for.
I need a textmode program to collect email from POP servers, and send email to non-local users via SMTP.

Also i'm looking for a prog that will do the same stuff, but just for sending mail, and that is able to call via the command line:

Something wich you can use this way:

Code: [Select]

[ July 12, 2002: Message edited by: -=f00bar=- ]

Linux user #283039

Gosh, I love Linux Quake.


Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #1 on: 12 July 2002, 23:54 »
i got a question about sending mail from the command line. I want to know what exactly can sendmail do? I want to know if there is a way I can send mail to all the Bobs. Basically tell it the e-mail addresses (a lot of them) and then tell it to send this message or perhaps an html document. And it would be nice to be able to store the addresses in a plain text .dat file.

[ July 12, 2002: Message edited by: Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command line mail sender !
« Reply #2 on: 13 July 2002, 01:57 »
It is very easy, the most basic being:

echo "Hello Bob!" | mail -s "Bob Subject" [email protected]

But what you want to do can easily be done using either a Perl or Shell script.  Do a search on google. There are thousands of examples.
Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #3 on: 13 July 2002, 02:56 »
can i put down more than 1 e-mail at the end?
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command line mail sender !
« Reply #4 on: 13 July 2002, 03:59 »
Well you can, but I would write a Perl script to do it so you can change the "From:", "Reply-To:", etc (properly format the headers the way you want).

It might look something like this one I wrote for another project, not mass mailing mind you:

Code: [Select]

The above code sample had a lot more code that searched a PostgreSQL database and sent mail to specific people but I hacked it down to just the basics that you are interested in. The above example will actually email HTML content in the body of the message although you can do plain text as well, just remove the "mailhtml" and change the "mailbody" variable to contain only text.  Additionally you could read the contents of a file in to the "mailbody" variable or there are a thousand different ways you could do it depending on your needs.  You can put more than one email address in any of the "To:", "Cc:" etc blocks, just separate them with commas.  You could have your email addresses in a file or database and change the script to read them in and send the message to those in your list.  Be creative.

[ July 12, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #5 on: 13 July 2002, 08:05 »
what does '/r' and '/n' do?
And can i specify an html file to send instead of writing the html in it just by specifying it, or do i have to tell it to 'cat body.html' or something?
Dammit now i want to learn perl.... But i am trying to learn C++ (only over online tutorials).

[ July 12, 2002: Message edited by: Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command line mail sender !
« Reply #6 on: 13 July 2002, 21:19 »
It's not "/r", it's "\r", just like in C.  "\r" is a CarriageReturn, and "\n" is a LineFeed or NewLine.  In DOS/WIN lines in text files are terminated with a "\r\n". In UNIX they are terminated with just a "\n" (M$ is so wasteful).  So it is best to use "\r\n" so that all mail programs can handle the headers.

To send an entire HTML file in place of the $mailbody variable you could do something like this:

Replace the

Code: [Select]

with

Code: [Select]

And yes, I would strongly recommend learning Perl. I believe it would be easier for a n00b programmer to learn, it's quick and easy and very powerful.  And you will learn things in Perl that will apply to C. A lot of the stucture, looping and decisions are very similar to C.

[ July 13, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #7 on: 13 July 2002, 21:22 »
any of the messages i have tried to send using mail or sendmail have not reached me. Is there something i need to configure for it?
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command line mail sender !
« Reply #8 on: 13 July 2002, 21:33 »
quote:
Originally posted by Master of Reality / Bob:
any of the messages i have tried to send using mail or sendmail have not reached me. Is there something i need to configure for it?


If the messages bounced they would end up in your mailbox (or root's mailbox).  Just run "pine" to read the local mail messages and it should contain the cause of the bounce.  Usually it will be spam control on the receiving server.  What you need to do to resolve it will depend on the bounce messages.  It will usually mean you need to change the configuration of sendmail (/etc/mail/sendmail.mc etc).

I will not be able to help any more until Sunday night or Monday if you need help with Sendmail.  You might find enough info on the net to get it configured on your own.

[ July 13, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

foobar

  • Member
  • **
  • Posts: 308
  • Kudos: 0
    • http://www.fuckmicrosoft.com
command line mail sender !
« Reply #9 on: 13 July 2002, 22:22 »
So void - lemme get this straight: (correct me plz!)

 - Sendmail can send mail to external users, that is, someone who is not connected to your local network, and picks his mail up from an external server (like pop or web-based)
 - So you do not have to specify an SMTP server just to get the message sent
 - But CAN you send via an external SMTP server ? (e.g. mail.quakeguy.myweb.nl is mine) and how ? (maybe it will help you get rid of spam control)

And some q's:
 - Is it possible, in linux scripting, to make labels by using c-style ':' ?
like:

Code: [Select]
Linux user #283039

Gosh, I love Linux Quake.


Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #10 on: 13 July 2002, 22:39 »
'sorry, your envelope send domain must exist'
this must mean that because i didnt specify a sender it didnt work... or because i didnt send it through a smtp server?

the other error fomr another e-mail address was 'Invalid mail address, must be fully qualified do main'.

Uhh... okay, i didnt specify the sender so it said that the sender was 'root@localhost' or 'root@server' and that is why it was invalid.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #11 on: 13 July 2002, 22:49 »
quote:
Originally posted by -=f00bar=-:
So void - lemme get this straight: (correct me plz!)

 - Sendmail can send mail to external users, that is, someone who is not connected to your local network, and picks his mail up from an external server (like pop or web-based)
 - So you do not have to specify an SMTP server just to get the message sent
 - But CAN you send via an external SMTP server ? (e.g. mail.quakeguy.myweb.nl is mine) and how ? (maybe it will help you get rid of spam control)

And some q's:
 - Is it possible, in linux scripting, to make labels by using c-style ':' ?
like:

Code: [Select]
[/b]

there is a line in /etc/mail/sendmail.mc that will allow you to specify an externel smtp server (line 13), it is commented out by default.
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
command line mail sender !
« Reply #12 on: 15 July 2002, 22:03 »
m0r, you can configure sendmail to send mail out directly without going through an external SMTP server. And the error messages you have received indicate that your sendmail is not configured properly. Sendmail is *highly* configurable.  In fact if you were to buy the "Bat Book" (O'Reilly book on Sendmail) you will find that it is about 2 inches thick.  The sendmail configuration file is "/etc/sendmail.cf".  However, it is such a complex configuration file you normally want to change the major options in "/etc/mail/sendmail.mc" and then generate a new sendmail configuration file (/etc/sendmail.cf) by typing:

# m4 /etc/mail/sendmail.mc > /etc/sendmail.cf

then restarting sendmail.

And yes f00bar, sendmail does not need an external SMTP server, in fact if you start the sendmail service on your box it will actually become an SMTP server (most email servers on the internet run Sendmail or qmail).  I use it on all of my mail servers.  I have around 20 of them.

m0r, you may want to look at this snippet of documentation.  I believe you'll need to look at the (DM*) directive:

http://www.redhat.com/docs/manuals/linux/RHL-7.3-Manual/ref-guide/s1-email-sendmail.html

[ July 15, 2002: Message edited by: VoidMain ]

Someone please remove this account. Thanks...

foobar

  • Member
  • **
  • Posts: 308
  • Kudos: 0
    • http://www.fuckmicrosoft.com
command line mail sender !
« Reply #13 on: 16 July 2002, 01:32 »
Ah great.
I will do some digging in the manpages and the config files, i'm sure i'll get wiser of it, and make it do what i want.
Linux user #283039

Gosh, I love Linux Quake.


Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
command line mail sender !
« Reply #14 on: 16 July 2002, 01:55 »
I got one of the messages that I sent.
It seems to work  
now i just have to make something to send out to all the Bobs
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'