使用cronjob和电子邮件来创建发短信的“服务器” [英] Using cronjob and email to create a texting "server"

查看:406
本文介绍了使用cronjob和电子邮件来创建发短信的“服务器”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这个想法是创建一个服务器,通过阅读我的电子邮件,并寻找电子邮件中的某些关键标题。当检测到具有某个头部的电子邮件时,其中的命令被解释并运行。这些不是Linux命令的心态,只是我提供了不同的命令。让我给你一个例子:




  • 我从我的手机发送文本Computer,define Hello / p>


  • 我的电子邮件收到文字,并将其另存为电脑,定义您好。


  • 计算机下载我的最新电子邮件,并看到计算机,定义
    你好,并运行命令定义你好。

  • 它将发送命令的
    的结果发送回我,这将是
    词Hello的定义。



代码实际上自己工作得很好,在cronjob上几乎可以正常工作。事实上,唯一有问题的命令是命令sendmail,这是将邮件发送回我的手机。



我看到人们谈论使用MAILTO发送电子邮件。我不使用MAILTO,而是使用gmail,mailx和msmpta的组合来完成工作。 sendmail工作正常,只是没有通过cronjob由于某种原因。这里是我得到的说明如何做到这一页:
http://tuxtweaks.com/2012/10/send-gmail-from-the-linux-command-line/



任何想法?

解决方案

我能够通过避免cronjob,使用无限while循环, (2000)(或其他大量的数字)来延迟脚本运行时。


So the idea of this was to create a "server" that would work by reading my email and looking for certain key headers in the email. When an email with a certain header is detected, the commands in it are interpreted and run. These are not Linux commands mind you, just different commands I have made available. Let me give you an example:

  • I send from my phone the text "Computer, define Hello" to my email.

  • My email receives the text, and saves it as "Computer, define Hello".

  • My computer downloads my newest email and sees "Computer, define Hello", and runs the command "define Hello".
  • It sends the results of sending the command back to me, which would be the definition of the word "Hello".

The code actually works fine on its own, and almost works fine on cronjob. In fact, the only command that's having a problem is the command "sendmail" which is what sends the mail back to my phone.

I saw that people have talked about using "MAILTO" to send email. I'm not using MAILTO but am instead using a combination of gmail, mailx, and msmpta to get the job done. sendmail works normally, just not through cronjob for some reason. Here is the page where I got instructions on how to do this: http://tuxtweaks.com/2012/10/send-gmail-from-the-linux-command-line/

Any ideas?

解决方案

I was able to make this work by avoiding cronjob altogether, using an infinite while loop, and using sleep(2000) (or some other large number) to delay when the script runs.

这篇关于使用cronjob和电子邮件来创建发短信的“服务器”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆