dongwo5940
dongwo5940
2011-09-14 15:43
浏览 86
已采纳

让服务器通过SSH发送邮件

I had written a program (In Android, client side and PHP, server side) to upload a file to a server over HTTP. Due to various reasons I had to change the system to do everything in SSH (for security among other things).

I have the basics set up (using jsch on Android). But I want to implement the equivalent of the PHP mail() function. When the file is uploaded, originally my PHP file automatically sends a mail from the server to a certain address.

I'm struggling to find a way to implement this within a shell on the server. So the question is, how do I automatically send an email from server in SSH?

EDIT: Forgot to mention server is CentOS.

图片转代码服务由CSDN问答提供 功能建议

我编写了一个程序(在Android,客户端和PHP,服务器端)将文件上传到服务器 通过HTTP。 由于各种原因,我不得不改变系统以在SSH中执行所有操作(为了安全性等)。

我已经设置了基础(在Android上使用jsch)。 但我想实现相当于PHP mail()函数。 上传文件时,最初我的PHP文件会自动将邮件从服务器发送到某个地址。

我很难找到在服务器上的shell中实现它的方法。 所以问题是,如何在SSH中自动从服务器发送电子邮件?

编辑: 感冒提及服务器是CentOS。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douweinu8562
    douweinu8562 2011-09-14 16:42
    已采纳

    SSH itself has no mail function - it only supports shell access (which might include X and SSH agent forwarding), file transfer (or other subsystems that might be integrated into the server) and port forwarding.

    So, you have basically these options:

    • Call some server-side shell command that causes the mail to be sent, as mentioned in the comment from Marc. This would use a shell channel.

    • Use port forwarding to access an SMTP server on your server host (or any host that accepts mail from there).

      If you want to send from the same program which uses JSch, there is no need to actually do client-side port forwarding, instead simply use a direct-tcpip channel, and set its host and port properties before connecting.

      Then you'll have to implement the SMTP protocol yourself, or use any other library which supports SMTP. (I suppose JavaMail can do this, but I didn't explore how you can configure it to use JSch as a tunnel.)

    点赞 评论

相关推荐