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

让服务器通过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.

  • 写回答

1条回答 默认 最新

  • 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.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?