求助一下 Linux 下代理上网 并 smtp 发邮件的问题

2020-02-19 14:46:09 +08:00
 a22124497

q 求助一下 linux 下代理上网 并 smtp 发邮件的问题

云主机,有公网开了个 squid,搞了 http 代理。另一台没公网的,直接

/etc/profile 中 http_proxy=http://192.168.1.115:3128 这样的

curl 可以上网了,直接 curl smtp.xxx.com 也可以通,配置 /etc/mail.rc ,在可以上网的机器上,直接 mail 发送邮件上就 ok 了,在不能上网的机器上,就不 ok。

网上查了一下,说是 squid 不支持 smtp 代理,好想加要改成透明,或是 nat 什么的,那样好像就略复杂了

有没啥简单的方法,可以代理 smtp 呀

1882 次点击
所在节点    问与答
1 条回复
ps1aniuge
2020-02-19 15:50:53 +08:00
$附件 = Get-ChildItem '/tmp/aaaa.tar.gz'
$HTML 邮件内容 =
@'
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>
<span style="font-family:Microsoft YaHei;font-size:18px;">html 信件内容</span>
</p>
</body>
</html>
'@

Send-MailMessage -Subject "主题" `
-From "你的 hotmail 账户 @hotmail.com" -To "你的 qq 邮箱 @qq.com" `
-SmtpServer "smtp.live.com" -Port 587 -UseSsl -Credential "你的 hotmail 账户 @hotmail.com" `
-Attachments $附件 -BodyAsHTML -body $HTML 邮件内容


上面的代码,保存成带有 bom 头的 a.ps1 文件,utf8 编码。
win 中用:
powershell.exe -file d:\你的目录\a.ps1

linux 中用:
/usr/bin/pwsh -file /你的目录 /a.ps1

------------------------------------------------------
centos7,centos8,安装 powershell:
curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/7/prod.repo
sudo yum remove -y powershell #删除旧版
sudo yum install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '



ubuntu1604:
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/16.04/prod.list
sudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '


ubuntu1804:
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/18.04/prod.list
sudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '



debian9:Deepin 深度操作系统,当前版本,基于 debian9。
sudo apt-get update
sudo apt-get install curl gnupg apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
sudo apt-get update
sudo apt-get remove -y powershell #删除旧版
sudo apt-get install -y powershell
pwsh -c 'mkdir -p "$env:HOME/.config/powershell" '
pwsh -c 'Add-Content -Value "Set-PSReadlineOption -EditMode Windows" -LiteralPath $profile '
pwsh -c 'Add-Content -Value "`nSubsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile" -LiteralPath /etc/ssh/sshd_config '

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/645812

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX