Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to utilize mailx to send mail via apython script

1,979 views
Skip to first unread message

Ferrous Cranus

unread,
Sep 5, 2013, 12:11:21 PM9/5/13
to


i as root just installed

sendmail and mailx. i have edited the ~/.mailrc to use:


ni...@superhost.gr [~/www/cgi-bin]# cat ~/.mailrc
account gmail {
set smtp-use-starttls
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=may)gmail
set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
}e



And now i'm trying to:


cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
SUBJECT, TO)
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )


Any ideas please why this fails to work?
while i remove the '-A gmail' string in the cmd line then i can send
fast mail but only to mail containing the @superhost.gr trail.

i need to be eble to send to external mails to.

Jorgen Grahn

unread,
Sep 5, 2013, 2:13:50 PM9/5/13
to
On Thu, 2013-09-05, Ferrous Cranus wrote:
>
>
> i as root just installed
>
> sendmail and mailx. i have edited the ~/.mailrc to use:
>
>
> ni...@superhost.gr [~/www/cgi-bin]# cat ~/.mailrc
> account gmail {
> set smtp-use-starttls
> set smtp=smtp://smtp.gmail.com:587
> set smtp-auth=login
> set smtp-auth-user=may)gmail
> set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again
> }e

Where did you learn about this .mailrc syntax? It doesn't match the
one documented in mailx(1) on my machines. (That's BSD mailx; there
seems to be two different flavors, but I don't think they are /that/
radically different.)

There are two ways to send mail on Unix:

1 Enqueue it to the local MTA using /usr/lib/sendmail. The local MTA
then becomes responsible for passing it on, if needed. This is the
traditional approach used by at, cron, mail, mailx, mutt ...

2 Send it via SMTP to some external mail relay. Local mail won't
work, every mail client must be configured, and temporary delivery
problems will be fatal.

You seem to have the software for (1), but the configuration for (2).

...
> cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
> SUBJECT, TO)
> p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
...

Make it work from the command line before attempting to automate it.

(You may also want to avoid invoking the shell. Think about what
might happen if MESSAGE=="; rm -rf $HOME ;".)

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Ferrous Cranus

unread,
Sep 6, 2013, 2:19:35 AM9/6/13
to
Στις 5/9/2013 9:13 μμ, ο/η Jorgen Grahn έγραψε:
>> cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
>> SUBJECT, TO)
>> p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
> ...
>
> Make it work from the command line before attempting to automate it.
>
> (You may also want to avoid invoking the shell. Think about what
> might happen if MESSAGE=="; rm -rf $HOME ;".)


Hello,

Even so, even trying it from the shell that is, 'mailx' fails to
delivers my test mails.

Can one helo me congigure sendmail properly?


mailX == an MUA == a Mail Client right?
sendmail == MTA == program that is responsilble to send mails?

So, i gather 'mailx' does use 'sendmail' to send mail yes?

can you provide me a working mail exmaple that works?

Why i can only send mail to local server addresses an not to an external
mail address?

--
Webhost <http://superhost.gr>

Todd

unread,
Sep 6, 2013, 3:22:45 AM9/6/13
to
Hi Ferrous,

Your .mailrc syntax is too weird. I place all my parameters
inside my script.

gMail is a pain in the ... to use with mailx. Here is a test
script I wrote that should help you. Change the "Your_email_address",
"Your_other_email_address", and "Your_email_password"
appropriately

Create a separate mailcert directory, copy your mailcerts
$ ls
cert7.db cert8.db key3.db secmod.db
from your Firefox directory to it, and point your "nss-config-dir"
at it.

Note that some of my lines scrolled when I pasted.

Good luck,
-T


$ cat MailxTest.gmail
#!/bin/bash

echo "mailx test" | mailx -v -s `dnsdomainname`" gmail smtp test subject" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from=Your_emai...@gmail.com \
-S smtp-auth-user=Your_emai...@gmail.com \
-S smtp-auth-password="Your_email_password" \
-S nss-config-dir=/home/linuxutil/mailcerts/ \
Your_other_e...@gmail.com





--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
the riddle wrapped in an enigma wrapped
in a couple slices of baloney
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ferrous Cranus

unread,
Sep 6, 2013, 4:09:50 AM9/6/13
to
-S smtp-auth-user=my_pe...@gmail.com \
-S smtp-auth-password="my_gmail_pass" \
-S nss-config-dir=/home/nikos/certs/ \
nko...@ath.forthnet.gr
}

==============================

cmd = "echo %s | mailx -v gmail -r %s -s %s %s" % ( MESSAGE, FROM,
SUBJECT, TO )
p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
output, errors = p.communicate()
print( errors, output )


================================


Output of my attempt to send mail:

ni...@superhost.gr [~/www/cgi-bin]# python mail.py
LOG: MAIN
cwd=/home/nikos/public_html/cgi-bin 9 args: send-mail -i -v -r -s
5N3CO...@YEG0WH73G3.com
BD1ZJHE1340OB76AYIM81YP51VBYFCR5B2BCH08LKVT06T5I9E gmail
nikos...@gmail.com
LOG: MAIN
<= -s...@secure.superhost.gr U=nikos P=local S=1125
Content-type: text/html; charset=utf-8

None b''
<h2><font color=blue>Ευχαριστώ πολύ για το ενδιαφέρον! Θα επικοινωνήσω
μαζί σου άμεσα :-)</font></h2>
LOG: MAIN
cwd=/var/spool/exim 4 args: /usr/sbin/exim -v -Mc 1VHr2Y-0004wE-RL
delivering 1VHr2Y-0004wE-RL
ni...@superhost.gr [~/www/cgi-bin]# LOG: MAIN
SMTP connection outbound 1378454714 1VHr2Y-0004wE-RL superhost.gr
nikos...@gmail.com
LOG: MAIN
SMTP connection outbound 1378454714 1VHr2Y-0004wE-RL superhost.gr
gm...@secure.superhost.gr
LOG: MAIN
remote host address is the local host: secure.superhost.gr
LOG: MAIN
== gm...@secure.superhost.gr R=lookuphost defer (-1): remote host
address is the local host
LOG: MAIN
SMTP connection outbound 1378454715 1VHr2Y-0004wE-RL superhost.gr
bd1zjhe1340ob76ayim81yp51...@secure.superhost.gr
LOG: MAIN
remote host address is the local host: secure.superhost.gr
LOG: MAIN
==
bd1zjhe1340ob76ayim81yp51...@secure.superhost.gr
<BD1ZJHE1340OB76AYIM81YP51...@secure.superhost.gr>
R=lookuphost defer (-1): remote host address is the local host
LOG: MAIN
SMTP connection outbound 1378454715 1VHr2Y-0004wE-RL superhost.gr
5n3co...@yeg0wh73g3.com
LOG: MAIN
** 5n3co...@yeg0wh73g3.com <5N3CO...@YEG0WH73G3.com>
R=fail_remote_domains: The mail server could not deliver mail to
5n3co...@yeg0wh73g3.com. The account or domain may not exist, they
may be blacklisted, or missing the proper dns entries.
Connecting to gmail-smtp-in.l.google.com [173.194.70.26]:25 ... connected
SMTP<< 220 mx.google.com ESMTP w44si1186161eef.195 - gsmtp
SMTP>> EHLO secure.superhost.gr
SMTP<< 250-mx.google.com at your service, [84.200.17.58]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 CHUNKING
SMTP>> STARTTLS
SMTP<< 220 2.0.0 Ready to start TLS
SMTP>> EHLO secure.superhost.gr
SMTP<< 250-mx.google.com at your service, [84.200.17.58]
250-SIZE 35882577
250-8BITMIME
250-ENHANCEDSTATUSCODES
250 CHUNKING
SMTP>> MAIL FROM:<-s...@secure.superhost.gr> SIZE=2165
SMTP<< 250 2.1.0 OK w44si1186161eef.195 - gsmtp
SMTP>> RCPT TO:<nikos...@gmail.com>
SMTP<< 250 2.1.5 OK w44si1186161eef.195 - gsmtp
SMTP>> DATA
SMTP<< 354 Go ahead w44si1186161eef.195 - gsmtp
SMTP>> writing message and terminating "."
SMTP<< 250 2.0.0 OK 1378454716 w44si1186161eef.195 - gsmtp
SMTP>> QUIT
LOG: MAIN
=> nikos...@gmail.com R=lookuphost T=remote_smtp
H=gmail-smtp-in.l.google.com [173.194.70.26] X=TLSv1:RC4-SHA:128
LOG: MAIN
**
BD1ZJHE1340OB76AYIM81YP51...@secure.superhost.gr:
retry timeout exceeded
LOG: MAIN
** gm...@secure.superhost.gr: retry timeout exceeded
LOG: MAIN
cwd=/var/spool/exim 8 args: /usr/sbin/exim -v -t -oem -oi -f <>
-E1VHr2Y-0004wE-RL
LOG: MAIN
<= <> R=1VHr2Y-0004wE-RL U=mailnull P=local S=2374 T="Mail delivery
failed: returning message to sender"
LOG: MAIN
Completed
LOG: MAIN
cwd=/var/spool/exim 4 args: /usr/sbin/exim -v -Mc 1VHr2a-0004wK-G7
delivering 1VHr2a-0004wK-G7
LOG: MAIN
remote host address is the local host: secure.superhost.gr
LOG: MAIN
== -s...@secure.superhost.gr R=dkim_lookuphost defer (-1): remote host
address is the local host
LOG: MAIN
** -s...@secure.superhost.gr: retry timeout exceeded
LOG: MAIN
-s...@secure.superhost.gr: error ignored
LOG: MAIN
Completed



I have pasted the .mailrc, the snippet of mail.py and the output

Can you help based on that info please?






--
Webhost <http://superhost.gr>

Jorgen Grahn

unread,
Sep 6, 2013, 4:50:54 AM9/6/13
to
On Fri, 2013-09-06, Ferrous Cranus wrote:
> ???????? 5/9/2013 9:13 ????, ??/?? Jorgen Grahn ????????????:
>>> cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM,
>>> SUBJECT, TO)
>>> p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE )
>> ...
>>
>> Make it work from the command line before attempting to automate it.
>>
>> (You may also want to avoid invoking the shell. Think about what
>> might happen if MESSAGE=="; rm -rf $HOME ;".)
>
>
> Hello,
>
> Even so, even trying it from the shell that is, 'mailx' fails to
> delivers my test mails.

Yes, that's exactly my point. It's a general problem solving trick:
if you can split your problem in two parts, try to solve one at a
time.

> Can one helo me congigure sendmail properly?
>
>
> mailX == an MUA == a Mail Client right?
> sendmail == MTA == program that is responsilble to send mails?
>
> So, i gather 'mailx' does use 'sendmail' to send mail yes?

Yes, the version of mailx I am used to[1] does that ... but apparently
you and the other posters are using some /other/ tool with the same
name.

> can you provide me a working mail exmaple that works?

Sorry; no. I use neither sendmail nor gmail.

> Why i can only send mail to local server addresses an not to an external
> mail address?

Don't know, but remember that local mail is a lot easier. As long as
you have an MTA (e.g. sendmail) running and its config is not horribly
broken, local->local will work.

/Jorgen

[1] Mailx is /old/. I used it on SunOS 20 years ago, and it wasn't
new then.

Ferrous Cranus

unread,
Sep 6, 2013, 5:06:01 AM9/6/13
to
Στις 6/9/2013 11:50 πμ, ο/η Jorgen Grahn έγραψε:
>> Why i can only send mail to local server addresses an not to an external
>> mail address?
> Don't know, but remember that local mail is a lot easier. As long as
> you have an MTA (e.g. sendmail) running and its config is not horribly
> broken, local->local will work.


I have managed already to make it work local=>local

But then how about local => internet

what configurations should i do? try to run what condig?

Is there an alternative that will help me send mails more easily?

--
Webhost <http://superhost.gr>

David Brown

unread,
Sep 6, 2013, 5:10:46 AM9/6/13
to
The obvious question here is why are you trying to use sendmail and
mailx? You are writing a script in Python, and you want to send mail
via an SMTP server. Just use Python's SMTP module.

Ferrous Cranus

unread,
Sep 6, 2013, 5:17:42 AM9/6/13
to
Liek this you mean:

# open Gmail's SMTP server
#server = smtplib.SMTP('smtp.gmail.com:587')
#server.ehlo()
#server.starttls()

# next, log in to the server
#server.login("m...@gmail.com", "my_pass")


Because GMail tend to add a Sender field when receiving my mail
supresing the real FROM field used in the webform to my Gmail's auth
account.

I want to avoid that by using my own mail server so my mails appear for
the correct client mail and not all of them from as coming from my GMail
account/


--
Webhost <http://superhost.gr>

Jonathan N. Little

unread,
Sep 6, 2013, 2:10:29 PM9/6/13
to
Ferrous Cranus wrote:
> Στις 6/9/2013 11:50 πμ, ο/η Jorgen Grahn έγραψε:
>>> Why i can only send mail to local server addresses an not to an external
>>> mail address?
>> Don't know, but remember that local mail is a lot easier. As long as
>> you have an MTA (e.g. sendmail) running and its config is not horribly
>> broken, local->local will work.
>
>
> I have managed already to make it work local=>local
>
> But then how about local => internet

If you are only going it that direction "local => internet" and
"internet" is gmail a simple solution is sSMTP.

https://wiki.debian.org/sSMTP
https://wiki.archlinux.org/index.php/SSMTP

I use it for remote servers to send error messages and info via scripts
to an "admin" gmail account.

Very simple to setup and works with gmail. Works for me to keep tabs on
various servers I maintain.


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Ferrous Cranus

unread,
Sep 7, 2013, 1:33:52 AM9/7/13
to
Στις 6/9/2013 9:10 μμ, ο/η Jonathan N. Little έγραψε:
> Ferrous Cranus wrote:
>> Στις 6/9/2013 11:50 πμ, ο/η Jorgen Grahn έγραψε:
>>>> Why i can only send mail to local server addresses an not to an
>>>> external
>>>> mail address?
>>> Don't know, but remember that local mail is a lot easier. As long as
>>> you have an MTA (e.g. sendmail) running and its config is not horribly
>>> broken, local->local will work.
>>
>>
>> I have managed already to make it work local=>local
>>
>> But then how about local => internet
>
> If you are only going it that direction "local => internet" and
> "internet" is gmail a simple solution is sSMTP.
>
> https://wiki.debian.org/sSMTP
> https://wiki.archlinux.org/index.php/SSMTP
>
> I use it for remote servers to send error messages and info via scripts
> to an "admin" gmail account.
>
> Very simple to setup and works with gmail. Works for me to keep tabs on
> various servers I maintain.
>
>
Can i use my own FROM field with sSMTP?
But connecting to google's smtp server will still add a Sender header.



--
Webhost <http://superhost.gr>

Jonathan N. Little

unread,
Sep 7, 2013, 8:33:20 AM9/7/13
to
Ferrous Cranus wrote:
> Στις 6/9/2013 9:10 μμ, ο/η Jonathan N. Little έγραψε:
>> Ferrous Cranus wrote:
>>> Στις 6/9/2013 11:50 πμ, ο/η Jorgen Grahn έγραψε:
>>>>> Why i can only send mail to local server addresses an not to an
>>>>> external
>>>>> mail address?
>>>> Don't know, but remember that local mail is a lot easier. As long as
>>>> you have an MTA (e.g. sendmail) running and its config is not horribly
>>>> broken, local->local will work.
>>>
>>>
>>> I have managed already to make it work local=>local
>>>
>>> But then how about local => internet
>>
>> If you are only going it that direction "local => internet" and
>> "internet" is gmail a simple solution is sSMTP.
>>
>> https://wiki.debian.org/sSMTP
>> https://wiki.archlinux.org/index.php/SSMTP
>>
>> I use it for remote servers to send error messages and info via scripts
>> to an "admin" gmail account.
>>
>> Very simple to setup and works with gmail. Works for me to keep tabs on
>> various servers I maintain.
>>
>>
> Can i use my own FROM field with sSMTP?


Yes. I even add "X-*" headers for sorting done within my scripts, Perl
and shell scripts so would be no problem with Python.

> But connecting to google's smtp server will still add a Sender header.


Not for the from From field, but the hostname is recorded in Received
field...but maybe I am misunderstanding your question.

Ferrous Cranus

unread,
Sep 7, 2013, 4:24:30 PM9/7/13
to
is there a way to send mail from the mail address i specify and without
the hostname of my server being revealed?

--
Webhost <http://superhost.gr>

Jonathan N. Little

unread,
Sep 7, 2013, 4:54:24 PM9/7/13
to
Well reading the man it says <http://linux.die.net/man/5/ssmtp.conf>
it says:

"Hostname
The full qualified name of the host. If not specified, the host is
queried for its hostname. "

So to test I used "bogus.nowhere.invalid" and that is what is in the
header for "Received:" fields. This is independent of the "From:" field
which you can set with your script if your enable it in the ssmtp.conf.
But note your external IP will be recorded though, no way around that I
would guess without a proxy.

Todd

unread,
Sep 7, 2013, 6:39:45 PM9/7/13
to
Don't use mailrc until you get it working from a batch file.

Todd

unread,
Sep 7, 2013, 6:41:29 PM9/7/13
to

> Please elaborate.
>
>
> --
> Webhost <http://superhost.gr>
>

replying over on comp.os.linux.networking

Todd

unread,
Sep 7, 2013, 7:20:51 PM9/7/13
to
On 09/06/2013 12:37 AM, Νίκος - Support wrote:> Στις 6/9/2013 10:20 πμ,
ο/η Todd έγραψε:
> Hello Todd,
>
> Do i download them from Google? What
> their use?
> i don't user FF i use Chrome instead.
>

> Please elaborate.

Certainly! gmail and zmail (zoho.com) are both huge
pains in the --- to get working from a script.

Hi Νίκος,

The batch script is how to send "From:" a gmail
account with a batch script using mailx. The
"To:" can be anyone.

I also have a script to do the same thing from a
zoho account (zmail), if anyone wants it.

First let me write the comments in my batch file a little better.
Remember, this BASH script is a only for sending from a script
through gMail.

-------- cat MailxTest.gmail -----------
#!/bin/bash
#
echo "mailx test" | mailx -v -s `dnsdomainname`" gmail smtp test subject" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from=From_emai...@gmail.com \
-S smtp-auth-user=From_emai...@gmail.com \
-S smtp-auth-password="From_email_password" \
-S nss-config-dir=/home/linuxutil/mailcerts/ \
To_email...@gmail.com

---------------------------------------------------

> i want to try your example but i don't know where i'm
> supposed to find the cert* and key* files.

You will find them in your gMail profile. Your profile
is in your home directory under
$HOME/.mozilla/firefox/your_profiles_cypher_name

1) install firefox

2) start firefox and let it automatically create its first
profile

3) open a terminal/xterm in your home directory

4) search for the certificates with
find $HOME/.mozilla/firefox -iname \*cert\*.db
remember to copy all the *.db's over from your profile
to a separate directory. Mine are:

cert7.db cert8.db key3.db secmod.db

Firefox needs these certificates to do the "s" in https

5) modify "nss-config-dir=/home/linuxutil/mailcerts/" in
the above script to match the directory you copied the
certificates to


> What are the mailcerts anyway?

gMail uses SSL (secure socket layer or the "s" in https) and
need these certificates to authenticate. So does zmail, but
uses a different sign in method.

> The code above is supposed to be use in a file called
> 'MailxTest.gmail'

This is a Bash script. The first line in the script "#!/bin/bash"
tells you this.

> not from within a python script i have called 'mail.py' ?

No. Not to a Python script. Get it working in Bash first,
them translate it to Python. YOUR PYTHON SUBROUTINE WILL NEED
THESE CERTIFICATES TOO! If you can get it working in BASH,
you are 90% of the way there.

> Also what is the other thing at the end
> you_other_e...@gmail.com

My bad. I should have said it was the gMail "To"
address, which can be anyone.

Good luck, I am dying to know if this helped you or
anyone else. I am usually the one asking the questions.

-T

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ferrous Cranus

unread,
Sep 8, 2013, 2:54:03 AM9/8/13
to
Hello Todd!

Let me tell you what i did:

i have:

rm ~./mailrc

ni...@superhost.gr [~]# cat MailXTest.gmail
#!/bin/bash
#
echo "mailx test" | mailx -v -s `dnsdomainname`" gmail smtp test subject" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from=Your_emai...@gmail.com \
-S smtp-auth-user=m...@gmail.com \
-S smtp-auth-password="my_gmail_pass" \
-S nss-config-dir=/home/nikos/certs/ \
ni...@ath.forthnet.gr

chmod u+x MailXTest.gmail

and finally when i try to run it:

ni...@superhost.gr [~]# MailXTest.gmail
-bash: MailXTest.gmail: command not found

What iam doing?

Apart from that i want to avoid using GMail's service becazue it adds up
a Sender: header sayign that the mail originating from my gmail accoutn
while i want to use the FROM field that the visitor used in my html web
form to fill in his email

Also it would be nice if the hostname would appear too.

Do we need to setup our own mail servr to achieve this?

--
Webhost <http://superhost.gr>

Ferrous Cranus

unread,
Sep 8, 2013, 2:58:12 AM9/8/13
to
I want to avoid using GMail's service because it adds up a Sender:
header saying that the mail originating from my gmail accoutn while i
want to use the FROM field that the visitor used in my html web form to
fill in his email

Also it would be nice if the hostname would appear too. Pehars by using
a proxy.
Can ssmtp handle this?

I cannot even download ssmtp when i 'yum install ssmtp'

where can i find it as a package and can you please provide me a
ssmtp.conf file that does the above( set its own FROM field and alter
hostname)

Thank you.

--
Webhost <http://superhost.gr>

Ferrous Cranus

unread,
Sep 8, 2013, 3:57:39 AM9/8/13
to
I cannot evn decide if i need an external mail server or setup my own
mail server.

--
Webhost <http://superhost.gr>

Jonathan N. Little

unread,
Sep 8, 2013, 10:11:01 AM9/8/13
to
What distro are you using? Ubuntu/Debian has it in the standard repos
and one of the links on configuration was for Arch

> where can i find it as a package and can you please provide me a
> ssmtp.conf file that does the above( set its own FROM field and alter
> hostname)
>

The ssmtp.conf should be in /etc/ssmtp/ssmtp.conf if you installed the
package.

Ferrous Cranus

unread,
Sep 8, 2013, 10:16:53 AM9/8/13
to
Στις 8/9/2013 5:11 μμ, ο/η Jonathan N. Little έγραψε:
>> I want to avoid using GMail's service because it adds up a Sender:
>> header saying that the mail originating from my gmail accoutn while i
>> want to use the FROM field that the visitor used in my html web form to
>> fill in his email
>>
>> Also it would be nice if the hostname would appear too. Pehars by using
>> a proxy.
>> Can ssmtp handle this?
>>
>> I cannot even download ssmtp when i 'yum install ssmtp'
>
> What distro are you using? Ubuntu/Debian has it in the standard repos
> and one of the links on configuration was for Arch
>
>> where can i find it as a package and can you please provide me a
>> ssmtp.conf file that does the above( set its own FROM field and alter
>> hostname)
>>
>
> The ssmtp.conf should be in /etc/ssmtp/ssmtp.conf if you installed the
> package.


i use CentOS 6.4 and yum install ssmtp cannot detect it.

Please if you comment in for my other questions too.

--
Webhost <http://superhost.gr>

David Brown

unread,
Sep 8, 2013, 10:34:47 AM9/8/13
to
I have no experience with GMail, but there you can put whatever you want
in the sender field (or any other field) when you connect to an SMTP
server. And the SMTP server can always choose to override fields with
its own settings if it wants. This applies equally to when you are
using Python's SMTP module to connect to the GMail server, or when you
send first to one SMTP server and relay on to GMail.

Since Python's SMTP module "speaks" SMTP to gmail, and any other mail
program or MTA that will send mail via a gmail relay also "speaks" SMTP
for that transfer, I would be very surprised if there is some effect you
can get with an additional program or relay that you cannot get by using
Python directly.

Your ISP should also have an SMTP server that you can connect to in the
same way (via Python), and send it on that way.


David Brown

unread,
Sep 8, 2013, 10:42:43 AM9/8/13
to
On 08/09/13 08:58, Ferrous Cranus wrote:
> I want to avoid using GMail's service because it adds up a Sender:
> header saying that the mail originating from my gmail accoutn while i
> want to use the FROM field that the visitor used in my html web form to
> fill in his email
>

If I understand you correctly here, you want a visitor to be able to put
a "To" address and a "From" address, and you want to pass on the mail
with those addresses and no others.

Let me know if you get it working - I'll sell the website's address to
spammers for a substantial fee.


Put another way, do /not/ do this. If you are sending email, then /you/
are sending it. If /your/ server is sending email, then the "from" and
"sender" addresses should be /your/ server or related email addresses.
It is basically fraud to say that someone else sent the email, even if
that someone had filled in the web form for the email.


> Also it would be nice if the hostname would appear too. Pehars by using
> a proxy.
> Can ssmtp handle this?
>

Most SMTP clients - ssmtp, Python's SMTP module, or anything else other
than a standard email program (which tend to be a bit limited) can put
anything you want in any field.


Ferrous Cranus

unread,
Sep 8, 2013, 11:37:10 AM9/8/13
to
If i setup some mail server on localhost can i alter the from field to
the one i want and suppress the hostname of the server?

Thai is what i want to know.

GMail doesnt care what you tell it to be the FROM field, it always ads
up an authenticated Sender address into the headers and also display the
hostname used to directly connect to it.


--
Webhost <http://superhost.gr>

Ferrous Cranus

unread,
Sep 8, 2013, 11:41:47 AM9/8/13
to
Στις 8/9/2013 5:42 μμ, ο/η David Brown έγραψε:
> Put another way, do /not/ do this. If you are sending email, then /you/
> are sending it. If /your/ server is sending email, then the "from" and
> "sender" addresses should be /your/ server or related email addresses.
> It is basically fraud to say that someone else sent the email, even if
> that someone had filled in the web form for the email.


No it is not.

My web form at http://superhost.gr ask the visitor for his mail address
and asks him for the subject to.

I want those the visitor used to be seen as FROM and MESSAGE and not my
gmail addres as sender.

Is there a way to make this work?

--
Webhost <http://superhost.gr>

Whiskers

unread,
Sep 8, 2013, 12:56:33 PM9/8/13
to
If you use the Gmail SMTP server to deliver an email, you cannot stop
Google from adding whatever header information they want.

Google may well object to your Gmail account being used to send emails
not coming from you, indeed they should reject any such email - and
terminate your Gmail account if it happens more than a few times. The
only exception may be that Google will let you 'register' particular
email addresses which are not provided by them, so that you can send
messages 'from' those addresses using their server; I don't know if
Google charge extra for that service. The headers available to the
recipient will show that Gmail have 'relayed' the message, and will show
the public IP number of the internet connection used for initiating the
email, and whatever hostname your system identifies itself with when
logging in to the Gmail server.

If your visitors have email addresses of their own already, why not let
them log in to their own email accounts instead of trying to use your
Gmail account?

--
-- ^^^^^^^^^^
-- Whiskers
-- ~~~~~~~~~~

Todd

unread,
Sep 8, 2013, 4:15:04 PM9/8/13
to
`dnsdomainname` gives you both your hostname and your domain
name. Try just running the command by itself from the command
line.

Note sure what you mean by "visitor used". Is the visitor's
address what you want to use as "From:"? If so, it needs to
be a gMail account and you need to use his info in
"from=", "smtp-auth-user=", and "smtp-auth-password=".

If "visitor" is not a gMail account, you need to find out
what the SMTP settings are for his account.

Not sure what is going on. Here is a scatter gun approach.

1) is "mailx" install and at the latest version? From
the command line, run the following to see if it
is there and in your path:
which mailx

2) try putting "./" in front of the MailXTest.gmail.
./MailXTest.gmail

3) "from=" and "smtp-auth-user=" should be the same
thing (m...@gmail.com).

4) try adding tracing to the script. On line one, add "-x"
#!/bin/bash -x
if there is a problem, it will show you where

-T

David Brown

unread,
Sep 8, 2013, 7:57:20 PM9/8/13
to
One last time - you can do /exactly/ the same thing from Python.

<http://docs.python.org/2/library/smtplib.html#smtp-example>

And again, /don't/ do this with other people's email addresses. Unless
you are specifically making a website with this intention (i.e., a
web-based email client), then this is verging on fraud. It is certainly
not what users would expect or like.

Todd

unread,
Sep 8, 2013, 9:23:56 PM9/8/13
to
On 09/08/2013 07:16 AM, Ferrous Cranus wrote:
>
>
> i use CentOS 6.4 and yum install ssmtp cannot detect it.
>
> Please if you comment in for my other questions too.


$ cat /etc/redhat-release
Scientific Linux release 6.4 (Carbon)

$ yum --enablerepo=* whatprovides ssmtpssmtp-2.61-19.el6.x86_64 :
Extremely simple MTA to get mail off the system to a Mailhub
Repo : epel



...

Todd

unread,
Sep 8, 2013, 9:35:54 PM9/8/13
to
On 09/08/2013 06:23 PM, Todd wrote:
> On 09/08/2013 07:16 AM, Ferrous Cranus wrote:
>>
>>
>> i use CentOS 6.4 and yum install ssmtp cannot detect it.
>>
>> Please if you comment in for my other questions too.
>
>
> $ cat /etc/redhat-release
> Scientific Linux release 6.4 (Carbon)
>
> $ yum --enablerepo=* whatprovides ssmtpssmtp-2.61-19.el6.x86_64 :
> Extremely simple MTA to get mail off the system to a Mailhub
> Repo : epel


You can download this from pbone.net, if you don't want to
get install EPEL repo.

Also, I never got ssmtp to work with gmail.

-T

Ferrous Cranus

unread,
Sep 9, 2013, 4:09:54 AM9/9/13
to
Στις 8/9/2013 7:56 μμ, ο/η Whiskers έγραψε:
> The
> only exception may be that Google will let you 'register' particular
> email addresses which are not provided by them, so that you can send
> messages 'from' those addresses using their server; I don't know if
> Google charge extra for that service.

What do you mean by Google letting me 'register' some mail address?
I dont unserstand that sentence.

Will it still add up Sender Header of it own?

--
Webhost <http://superhost.gr>

Ferrous Cranus

unread,
Sep 9, 2013, 4:29:20 AM9/9/13
to
ni...@superhost.gr [~]# ./MailXTest.gmail
Send options without primary recipient specified.
Usage: mailx -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s
SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
./MailXTest.gmail: line 4: -S: command not found
ni...@superhost.gr [~]# cat MailXTest.gmail
#!/bin/bash -x
#
echo "mailx test" | mailx -v -s `dnsdomainname`" gmail smtp test subject" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from=Your_emai...@gmail.com \
-S smtp-auth-user=myg...@gmail.com \
-S smtp-auth-password="pass" \
-S nss-config-dir=/home/nikos/certs/ \
ni...@ath.forthnet.gr

The visitor of http://superhost.gr tried to send me an email using the
wb gorm i ahve which asks for his mail address and MESSAGE he wans to
send me.

i have no way of knowing the smtp settings the visitor uses or even if
his mail address is real but no matter what, the the FROM field must
contain the mail address the user types in the web form.


--
Webhost <http://superhost.gr>

Todd

unread,
Sep 9, 2013, 2:44:36 PM9/9/13
to
On 09/09/2013 01:29 AM, Ferrous Cranus wrote:
> i have no way of knowing the smtp settings the visitor uses or even if
> his mail address is real but no matter what, the the FROM field must
> contain the mail address the user types in the web form.

You should create a special eMail address of your own for
these messages and use that to send with. "Supposedly"
(note the weasel word), "-S from=" and "-S smtp-auth-user="
can be different.

Jorgen Grahn

unread,
Sep 9, 2013, 3:35:04 PM9/9/13
to
On Sun, 2013-09-08, Ferrous Cranus wrote:
...
> I want to avoid using GMail's service because it adds up a Sender:
> header saying that the mail originating from my gmail accoutn while i
> want to use the FROM field that the visitor used in my html web form to
> fill in his email

You've mentioned this several times. What's the problem? It seems like
a sane and sensible thing for GMail to do, and also a harmless one.
RFC 2822 indicates Sender: and From: can be seen as "the guy who sent
the message; pressed the button" and "the guy who wrote it and is
responsible for it".

And doesn't that describe what you're aiming for?

The originator fields of a message consist of the from field, the
sender field (when applicable), and optionally the reply-to field.
... If the from field contains more than one mailbox specification
in the mailbox-list, then the sender field ... MUST appear in the
message. In either case, an optional reply-to field MAY also be
included ...

The originator fields indicate the mailbox(es) of the source of the
message. The "From:" field specifies the author(s) of the message,
that is, the mailbox(es) of the person(s) or system(s) responsible
for the writing of the message. The "Sender:" field specifies the
mailbox of the agent responsible for the actual transmission of the
message. For example, if a secretary were to send a message for
another person, the mailbox of the secretary would appear in the
"Sender:" field and the mailbox of the actual author would appear in
the "From:" field. ...

The originator fields also provide the information required when
replying to a message. When the "Reply-To:" field is present, it
indicates the mailbox(es) to which the author of the message suggests
that replies be sent. In the absence of the "Reply-To:" field,
replies SHOULD by default be sent to the mailbox(es) specified in the
"From:" field unless otherwise specified by the person composing the
reply.

This part is also nice:

In all cases, the "From:" field SHOULD NOT contain any mailbox that
does not belong to the author(s) of the message.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Whiskers

unread,
Sep 9, 2013, 4:31:25 PM9/9/13
to
On 2013-09-09, Ferrous Cranus <ni...@superhost.gr> wrote:
> Στις 8/9/2013 7:56 μμ, ο/η Whiskers έγραψε:
>> The
>> only exception may be that Google will let you 'register' particular
>> email addresses which are not provided by them, so that you can send
>> messages 'from' those addresses using their server; I don't know if
>> Google charge extra for that service.
>
> What do you mean by Google letting me 'register' some mail address?
> I dont unserstand that sentence.

Go to <https://support.google.com/mail/answer/22370?hl=en-GB&ctx=mail>
"Sending mail from a different address".

,----
| Gmail lets you send messages with another of your email addresses listed
| as the sender instead of your Gmail address. This feature helps you
| manage multiple accounts from the Gmail interface; it works only if you
| already own the email account linked to the alternate address. [...]
`----

> Will it still add up Sender Header of it own?

I wouldn't be at all surprised. If you don't want Google to 'stamp'
your mail, don't send it using Google.

Whiskers

unread,
Sep 9, 2013, 5:07:34 PM9/9/13
to
On 2013-09-09, Ferrous Cranus <ni...@superhost.gr> wrote:
> Στις 8/9/2013 11:15 μμ, ο/η Todd έγραψε:
>> On 09/07/2013 11:54 PM, Ferrous Cranus wrote:
>>> Στις 8/9/2013 2:20 πμ, ο/η Todd έγραψε:
>>>> On 09/06/2013 12:37 AM, Νίκος - Support wrote:> Στις 6/9/2013 10:20 πμ,
>>>> ο/η Todd έγραψε:
>>>> >> On 09/05/2013 09:11 AM, Ferrous Cranus wrote:

[...]

> The visitor of http://superhost.gr tried to send me an email using the
> wb gorm i ahve which asks for his mail address and MESSAGE he wans to
> send me.
>
> i have no way of knowing the smtp settings the visitor uses or even if
> his mail address is real but no matter what, the the FROM field must
> contain the mail address the user types in the web form.

That's fine, but only while the email is on your own system. If you
want users of your system to be able to send local emails to you and
other local users, each user should have a username of their own which
they use to log in to your system, and the computer they use will have a
hostname; those two things combine to create email addresses that are
valid for use within your own system - "jim_z@localhost" or
"ro...@upstairs.computer" or "d...@kitchen.sink" or whatever. This sort
of arrangement is not usually worth the bother, apart from getting
system status and error reports sent to the system administrator by the
various 'daemons' or 'services' you have running.

If you want to allow visitors to access their existing Gmail accounts
from your computer, just set up a limited user called (for example)
guest, with access only to a web browser - possibly in 'kiosk mode' - so
that they can log in using the same login details as they do from
anywhere else.

Or are you trying to become an email service provider yourself?

Jonathan N. Little

unread,
Sep 9, 2013, 5:11:01 PM9/9/13
to
Todd wrote:
> On 09/08/2013 06:23 PM, Todd wrote:
>> On 09/08/2013 07:16 AM, Ferrous Cranus wrote:
>>>
>>>
>>> i use CentOS 6.4 and yum install ssmtp cannot detect it.
>>>
>>> Please if you comment in for my other questions too.
>>
>>
>> $ cat /etc/redhat-release
>> Scientific Linux release 6.4 (Carbon)
>>
>> $ yum --enablerepo=* whatprovides ssmtpssmtp-2.61-19.el6.x86_64 :
>> Extremely simple MTA to get mail off the system to a Mailhub
>> Repo : epel
>
>
> You can download this from pbone.net, if you don't want to
> get install EPEL repo.
>
> Also, I never got ssmtp to work with gmail.

Really? I usually use nullmailer but it does not work with gmail.
ssmtp was the only thing that I got to work with gmail on several
computers. Generally what I do to assist in remote administration for
servers. I create a gmail account for error messages and notices, use
ssmtp to setup a lightweight smtp "server" My scripts email warnings,
errors, and messages to that account and the server admins only have to
monitor that email account from anywhere...

Jonathan N. Little

unread,
Sep 9, 2013, 5:33:10 PM9/9/13
to
It sounds more like the OP is trying to setup form to mail and wishes to
validate if the visitor's supplied email address in his form is valid.
Well, there is no real way to do this one shot. If he is using that form
to create a auto-reply with that user supplied address he better take
measures to prevent robo comment spam.

Todd

unread,
Sep 9, 2013, 5:40:51 PM9/9/13
to
On 09/09/2013 02:11 PM, Jonathan N. Little wrote:
>> Also, I never got ssmtp to work with gmail.

> Really? I usually use nullmailer but it does not work with gmail.

It took me several days to figure out how to get mailx to
work with gmail and zmail. I was pretty frazzled by
the end of it. Probably contributed with me not getting
ssmtp working

Jonathan N. Little

unread,
Sep 9, 2013, 6:15:44 PM9/9/13
to
Todd wrote:
> On 09/09/2013 02:11 PM, Jonathan N. Little wrote:
>>> Also, I never got ssmtp to work with gmail.
>
>> Really? I usually use nullmailer but it does not work with gmail.
>
> It took me several days to figure out how to get mailx to
> work with gmail and zmail. I was pretty frazzled by
> the end of it. Probably contributed with me not getting
> ssmtp working
>

Other than installing it edit the /etc/ssmtp/ssmtp.conf to something
like this change what is obvious:

# /etc/ssmtp/ssmtp.conf
# Sample Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
root=YOUR_...@gmail.com
UseTLS=YES
UseSTARTTLS=YES
mailhub=smtp.gmail.com:587
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
#
# Username and password for Google's Gmail servers
# From addresses are settled by Mutt's rc file, so
# with this setup one can still achieve multi-user SMTP
AuthUser=YOUR_...@gmail.com
AuthPass=YOUR_GMAIL_PASSWORD

Then you might like to setup alias like as follows:

#/etc/ssmtp/revaliases
# sSMTP aliases
#
# Format: local_account:outgoing_address:mailhub
#
# Some common handy examples to redirect system script messages
root:YOUR_...@gmail.com
postmaster:YOUR_...@gmail.com


And you can test it out with the bash one-liner

echo -e "TO: Admin <YOUR_...@gmail.com>\nFROM: test
<bogus@invalid>\nSUBJECT: A Test\nA sample message" | $(which sendmail)
YOUR_...@gmail.com

Whiskers

unread,
Sep 10, 2013, 11:38:20 AM9/10/13
to
Might be useful to clarify whether the OP wants the visitor's message to
be sent *to* the OP's Gmail address, eg as feedback from a website, or
wants the visitor to be able to send emails to anyone by *relaying*
through Google's SMTP server using the OP's Google account but with
unspecified or invented 'From' addresses.

The latter should not be permitted by Google or any other email service
provider, of course.

<http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/>
<https://wiki.archlinux.org/index.php/SSMTP#Forward_to_a_Gmail_Mail_Server>
<http://heirloom.sourceforge.net/mailx.html>

Ferrous Cranus

unread,
Sep 10, 2013, 3:37:29 PM9/10/13
to
What i want is for my weboage to notify me for the visitors spcified
mail address and message and this be done by setting up my won mail
server because gmail's tend to alter the from address.

--
Webhost <http://superhost.gr>

David Brown

unread,
Sep 10, 2013, 5:04:07 PM9/10/13
to
Your own email server will either send via another "real" SMTP server,
such as gmail's (which will change the Sender and/or From fields), or it
will try to deliver email directly - in which case half the receiving
email servers will block it as a spam server (even if you go to all the
effort of fixed IP's, proper DNS, and proper reverse DNS, you will be
caught sending with From addresses that should not be coming from your
machine).

I don't know why this is so difficult for you to comprehend - you cannot
forge other people's From addresses and expect everything to work!

Just implement the web site in the same way everybody else does - fields
that the user enters (such as their own address) go as part of the email
contents, and the whole thing is emailed to a fixed address from a fixed
address (these can even be the same, such as your gmail address).

This is not rocket science - people have been doing it correctly for a
long time. The reason you are having such a hard time is because you
are desperately trying to misunderstand how email works, and how web
email forms work.

<http://www.freecontactform.com/html_form.php>
<http://www.templatemonster.com/help/how-create-contact-form-html.html>

(These use php rather than python, but the principle is the same.)

Whiskers

unread,
Sep 10, 2013, 5:05:58 PM9/10/13
to
On 2013-09-10, Ferrous Cranus <ni...@superhost.gr> wrote:
> Στις 10/9/2013 6:38 μμ, ο/η Whiskers έγραψε:
>> On 2013-09-09, Jonathan N. Little <lws...@gmail.com> wrote:
>>> Whiskers wrote:
>>>> On 2013-09-09, Ferrous Cranus <ni...@superhost.gr> wrote:
>>>>> Στις 8/9/2013 11:15 μμ, ο/η Todd έγραψε:
>>>>>> On 09/07/2013 11:54 PM, Ferrous Cranus wrote:
>>>>>>> Στις 8/9/2013 2:20 πμ, ο/η Todd έγραψε:
>>>>>>>> On 09/06/2013 12:37 AM, Νίκος - Support wrote:> Στις 6/9/2013 10:20 πμ,
>>>>>>>> ο/η Todd έγραψε:

[...]

>>> It sounds more like the OP is trying to setup form to mail and wishes to
>>> validate if the visitor's supplied email address in his form is valid.
>>> Well, there is no real way to do this one shot. If he is using that form
>>> to create a auto-reply with that user supplied address he better take
>>> measures to prevent robo comment spam.
>>
>> Might be useful to clarify whether the OP wants the visitor's message to
>> be sent *to* the OP's Gmail address, eg as feedback from a website, or
>> wants the visitor to be able to send emails to anyone by *relaying*
>> through Google's SMTP server using the OP's Google account but with
>> unspecified or invented 'From' addresses.
>>
>> The latter should not be permitted by Google or any other email service
>> provider, of course.
>>
>> <http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/>
>> <https://wiki.archlinux.org/index.php/SSMTP#Forward_to_a_Gmail_Mail_Server>
>> <http://heirloom.sourceforge.net/mailx.html>
>>
> What i want is for my weboage to notify me for the visitors spcified
> mail address and message and this be done by setting up my won mail
> server because gmail's tend to alter the from address.

Your web page cannot send an email 'From:' the visitor's email address.
It has to send emails 'From' an address which you own and using an SMTP
server associated with that email address.

If you want to know the visitor's email address, design the form to
include that as part of the 'body' of the email message the web page
sends to you (or perhaps as the 'Reply-To:' header of that message).

<https://ixquick.com/do/search?q=how+to+send+email+from+web+form>

Checking whether or not the visitor has given a real email address, is a
separate matter.
0 new messages