|EasyScripts|用GMaild从控制台发送邮件的脚本

6 views
Skip to first unread message

邵志雄

unread,
Apr 29, 2009, 10:21:53 AM4/29/09
to 二进制生存

有时候需要备份些东西到邮箱,能够让脚本定时自动运行当然是最好!
抽时间用python写了这么个脚本,使用python-libgmail库 ( sudo apt-get install python-libgmail )

发送邮件的代码都是现成的调用,主要是在易用性上做了些优化:

1、发送一句话,不需要正文,比如给邮件列表发个“求助。。。。。(如题)”之类的:
    msend -t  li...@domain.com  -s "求助,图形界面进不了,哈哈”

2、发个文件到自已的邮箱,一般用 -f "file1;file2;file3;dir2;dir3" ,发懒的时候不写 -f 也能用
    msend -t m...@gmail.com -f readme.txt
    msend -t m...@gmail.com  *.txt

3、发个文件或目录到某个邮箱,需要ZIP一下,(当然2和3可以混用)
    msend -t fri...@domain.com  -z  ./pics/

基本上:
1、目标邮箱和主题必须写上;
2、如果有文件附件,可以不指定主题,脚本会把文件数当主题名(gmail的title里会显示正文的)
3、程序会自动判断文件和目录,如果是目录就会遍历
4、不管是文件还是目录,如果前缀指定了-z,就压缩后发送
5、没有前缀的参数一律当文件名

如果有需要,可以下载玩玩,运行msend不带参数就有用法,应该很明白了。

(还有什么稀奇古怪的想法?欢迎提出来!)


    Usage:
        msend -t us...@domain.com -s title
        msend -t us...@domain.com {-s title | -f file | -z file}

    Full command:
        msend --to=us...@domain.com --subject=title [--msg=body] [--files="file1;dir2"] [--zip="file1;dir2"]

    Example: ( edit ~/.msend for default sender account )
        msend -t us...@domain.com -s "just a test"
        msend -t us...@domain.com -s "send all pic" -f ./mypics/
        msend -t us...@domain.com -s "send files as zip" -z ./mytext/
        msend -t us...@domain.com -s "send both" -f mytext -z mytext


---------------------------------
   google talk
sha...@gmail.com
---------------------------------
msend

qq274980

unread,
Apr 29, 2009, 10:38:21 AM4/29/09
to 二进制生存
第一次运行时,脚本会在$HOME下新建一个文件,里面只有一行就是:
your...@domain.com password
改一下,把文件权限改一下, chmod 600 ~/.msend,就开始用吧。

On 4月29日, 下午10时21分, 邵志雄 <sha...@gmail.com> wrote:
> 有时候需要备份些东西到邮箱,能够让脚本定时自动运行当然是最好!
> 抽时间用python写了这么个脚本,使用python-libgmail库 ( sudo apt-get install python-libgmail
> )
>
> 发送邮件的代码都是现成的调用,主要是在易用性上做了些优化:
>
> 1、发送一句话,不需要正文,比如给邮件列表发个"求助。。。。。(如题)"之类的:

> msend -t l...@domain.com -s "求助,图形界面进不了,哈哈"


>
> 2、发个文件到自已的邮箱,一般用 -f "file1;file2;file3;dir2;dir3" ,发懒的时候不写 -f 也能用
> msend -t m...@gmail.com -f readme.txt
> msend -t m...@gmail.com *.txt
>
> 3、发个文件或目录到某个邮箱,需要ZIP一下,(当然2和3可以混用)
> msend -t fri...@domain.com -z ./pics/
>
> 基本上:
> 1、目标邮箱和主题必须写上;
> 2、如果有文件附件,可以不指定主题,脚本会把文件数当主题名(gmail的title里会显示正文的)
> 3、程序会自动判断文件和目录,如果是目录就会遍历
> 4、不管是文件还是目录,如果前缀指定了-z,就压缩后发送
> 5、没有前缀的参数一律当文件名
>
> 如果有需要,可以下载玩玩,运行msend不带参数就有用法,应该很明白了。
>
> (还有什么稀奇古怪的想法?欢迎提出来!)
>
> Usage:

> msend -t u...@domain.com -s title
> msend -t u...@domain.com {-s title | -f file | -z file}
>
> Full command:
> msend --to=u...@domain.com --subject=title [--msg=body]


> [--files="file1;dir2"] [--zip="file1;dir2"]
>
> Example: ( edit ~/.msend for default sender account )

> msend -t u...@domain.com -s "just a test"
> msend -t u...@domain.com -s "send all pic" -f ./mypics/
> msend -t u...@domain.com -s "send files as zip" -z ./mytext/
> msend -t u...@domain.com -s "send both" -f mytext -z mytext


>
> ---------------------------------
> google talk
> sha...@gmail.com
> ---------------------------------
>

> msend
> 5K查看下载

qq274980

unread,
May 4, 2009, 2:55:48 AM5/4/09
to 二进制生存
Linux 有一个自带的 mail 程序,它是这样用的
$ tar cvzf - data1 data2 | uuencode data.tar.gz | mail -s 'data'
感叹一下,这才是UNIX命令界面的精华--用简洁的程序组合实现复杂的功能

邵志雄

unread,
May 5, 2009, 10:20:51 PM5/5/09
to 二进制生存

做了一点小的修改:

以前发送出错时只显示FAIL,现在连同参数一起显示出来,便于重新发送
(不然都忘记刚才是发的哪个文件了)
msend
Reply all
Reply to author
Forward
0 new messages