Configure mailx to Use Gmail’s smtp

By: Zhiqiang Ma In: Linux

The updated English version of this post:

sending-email-from-mailx-command-in-linux-using-gmails-smtp/

在~/.mailrc中设置如下:

set smtp-use-starttls
set nss-config-dir=~/.mozilla/firefox/9jkisjeo.default
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=USER_NAME@gmail.com
set smtp-auth-password=PASSWORD
set from="USERNAME@gmail.com(NAME)"
# sendwait

nss-config-dir中设置为自己相关的firefox目录, 要使用到其中的cert8.db等几个文件.
很明显了.

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

其实我配置smtp.gmail.com主要看中可能利用shell来批量发送邮件.
这是我的一个批量上传文件的脚本:

#!/bin/bash

# transfer many files via attachment
# you must set up mailx to be able to email

# author Eric Z.Q. Ma eric.zq.ma@gmail.com
# Feb. 25 2009

echo "Please enter the message sent with mail:"
read message
echo "Please enter the email address you mail to:"
read address
# echo Please enter the email address to reply:
# read reply

if [[ $address == "" ]]
then
    address="username@gmail.com"
fi

# if [[ $reply == "" ]]
# then
#     rreply=""
# else
#    rreply="-r $reply"
# fi

echo "Please select the transfer type:"
echo "1. wait for the last email transferred before transfer another one."
echo "2. transfer several emails at one time and wait a constant time."
read transferType                                                                                                                                    

WAIT_COUNT=-1
WAIT_TIME=0
# set envs
sendwait=no

if [[ $transferType == 2 ]]
then
    echo "Please enter the number of mails transfer at one time:"
    read WAIT_COUNT
    echo "Please enter the time for waiting (s):"
    read WAIT_TIME
# set envs
    sendwait=yes
fi

echo "Transfer begins."

count=0

until [[ $1 == "" ]]
do
    file="$1"
    # echo $file
    if [ -f "$file" ]
    then
        echo "mail  $file  to  $address"  # from  $reply
#       echo "$file -- $message" | mailx -s "$file -- $message" -a "$file"  $rreply $address
        echo "$file -- $message" | env sendwait=$sendwait mailx -s "$file -- $message" -a "$file" $address
    fi
    let "count=count+1"
    if [[ $count == $WAIT_COUNT ]]
    then
        count=0
        echo "Wait $WAIT_TIME seconds to transfer the last $WAIT_COUNT mails."
        echo ""
        sleep $WAIT_TIME
    fi
    shift
done
Author: Zhiqiang Ma Posted on: Mar 10, 2009 Views: 2,088
Tags: , , , ,
Like this post? Subscribe full-text feeds from all Fclose.com blogs:
Add your comments, share your thoughts

Be nice. Keep it clean. Stay on topic. No spam.