在Linux系统中发送图片到邮箱可以通过多种方式实现,以下是一些常见的方法:
mail
命令(需要配置邮件传输代理MTA)postfix
或sendmail
),确保系统能够发送邮件。uuencode
命令将图片文件编码为适合邮件传输的格式,并通过mail
命令发送:uuencode /path/to/image.jpg image.jpg | mail -s "Subject of the email" recipient@example.com
mutt
命令mutt
是一个功能强大的邮件客户端,可以用来发送带有附件的邮件。
mutt
(如果尚未安装):sudo apt-get install mutt # 对于Debian/Ubuntu系统
sudo yum install mutt # 对于CentOS/RHEL系统
mutt
发送图片:echo "This is the body of the email" | mutt -s "Subject of the email" -a /path/to/image.jpg -- recipient@example.com
sendEmail
脚本sendEmail
是一个轻量级的命令行邮件发送工具。
sendEmail
:wget https://github.com/kristianhristov/sentEmail/raw/master/sendEmail
chmod +x sendEmail
sendEmail
发送图片:./sendEmail -f sender@example.com -t recipient@example.com -u "Subject of the email" -m "This is the body of the email" -a /path/to/image.jpg -s smtp.example.com:587 -xu sender@example.com -xp password -o tls=yes
可以使用Python的smtplib
和email
库来发送带有图片附件的邮件。
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
# 设置邮件内容
msg = MIMEMultipart()
msg['From'] = 'sender@example.com'
msg['To'] = 'recipient@example.com'
msg['Subject'] = 'Subject of the email'
# 邮件正文
body = 'This is the body of the email'
msg.attach(MIMEText(body, 'plain'))
# 添加图片附件
filename = "image.jpg"
attachment = open(filename, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
# 发送邮件
server = smtplib.SMTP('smtp.example.com', 587)
server.starttls()
server.login('sender@example.com', 'password')
text = msg.as_string()
server.sendmail('sender@example.com', 'recipient@example.com', text)
server.quit()
python send_email.py
通过以上方法,你可以在Linux系统中轻松地将图片发送到指定的邮箱地址。
云+社区沙龙online [技术应变力]
云+未来峰会
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL训练营
腾讯云数据库TDSQL(PostgreSQL版)训练营
领取专属 10元无门槛券
手把手带您无忧上云