Using cronjob and email to create a texting “serve

2019-08-16 23:37发布

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?

1条回答
Explosion°爆炸
2楼-- · 2019-08-17 00:39

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.

查看更多
登录 后发表回答