curl通过SMTP发送邮件

确认curl是否支持SMTP

首先确认你的curl是否支持smtp

$ curl-config --protocols | grep SMTP
SMTP
SMTPS

在这里插入图片描述

如果不支持smtp协议,那么重新安装curl

安装高版本CURL

使用yum安装的curl一般不支持smtp协议,接下来我们使用源码包来安装curl

$ cd /usr/local/src
$ wget https://github.com/bagder/curl/archive/master.zip
$ unzip master.zip
$ cd curl-master
$ ./buildconf
$ ./configure 
$ make && make install

再次确认下是否支持curl

$ /usr/local/bin/curl-config --protocols | grep SMTP
SMTP
SMTPS

备注:默认情况下,curl会被安装到/usr/local/bin下,与老版本同时存在

使用curl发送邮件

$ /usr/local/bin/curl -s \
--url "smtp://smtp.qiye.aliyun.com" \
--mail-from "support@example.com" \
--mail-rcpt "test@example.com" \
--upload-file mail.txt \
--user "support@example.com:123456"

Mail.txt

From: "support@example.com" 
To: "test@example.com"
Subject: This is a test2hello! 1223

I'm sending this mail for test.

参数说明

--url :smtp地址
--mail-from:发件人邮箱
--mail-rcpt:收件人邮箱
--upload-file:信件内容,包含发件人、收件人、标题、内容
--user:账号密码,中间用冒号分隔
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值