How to send email reminders using sendmail

Hi, I’m trying to set up an email reminder system, where I can send emails at certain dates. I’ve been looking at the sendmail function but I haven’t found any information as to how I can edit the send date. I.e I have a simple csv, with email addresses and appointment reminders and want to send email reminders based on those dates.
Any help would be much appreciated!

 採用された回答

Adam Danz
Adam Danz 2019 年 7 月 22 日

0 投票

Is that a 3rd party function or are you refering to sendmail()? It is not possible to set the send-date using sendmail(). The email is sent when the command it executed. Instead, you could write a program that could be run daily where a table contains the email information in one column and the send-date in another column. If today's date is the send date, the program could send the email and then remove the entry from the table.
Alternatively you could create a timer object that controls when the email is sent but if matlab shuts down (or if the timer object is deleted) the emails will never be sent.

6 件のコメント

Sue MM
Sue MM 2019 年 7 月 22 日
Thank you! Can you please elaborate regarding the daily program/ if there any examples I can reference? I’ll also look into the timer alternative. Thanks again!
Adam Danz
Adam Danz 2019 年 7 月 22 日
編集済み: Adam Danz 2019 年 7 月 22 日
Here's a very basic example. You could keep a spreadsheet that lists an email address and a send-date (and any other data you need). Step 1 of your code would be reading your spreadsheet into matlab. It would look sometime like this below. Alternatively, you could just store the data in matlab to begin with.
C =
{'johndoe@fakemail.com' } {'08/01/2019'}
{'janedough@fakemail.com'} {'07/23/19' }
...
Step 2 of your code would be to identify rows in the date column that match today's date. That would look something like this
todayRowIdx = datetime(c(:,2)) == datestr(floor(now));
Step 3 would be a loop. You'll loop through each identified row that matches today.
todayRowSub = find(todayRowIdx);
for i = 1:numel(todayRowSub)
sendmail(...) % C{todayRowSub(i)} this is the email address
end
Adam Danz
Adam Danz 2019 年 7 月 22 日
編集済み: Adam Danz 2019 年 7 月 22 日
Two more suggestions
1) when the reminder is sent, it should be recorded so if the program is run again, it won't send another email.
2) instead of searching for a date that matches today, you should search for a date that is today or earlier and was not marked as "already sent" (from step 1). That way if the program is not run over the weekend, the emails will be sent on Monday (for example).
Sue MM
Sue MM 2019 年 7 月 22 日
Thank you, I really appreciate that! Using this method I can use the sendmail() correct? Also- it would be okay to say send the email 2/3 days in advance by editing the datestr(floor(now))?
Adam Danz
Adam Danz 2019 年 7 月 22 日
"Using this method I can use the sendmail() correct?"
Yes, you can see where I call sendmail() in my for-loop. Also, here's a demo I wrote a while back.
"would be okay to say send the email 2/3 days in advance by editing the datestr(floor(now))?"
That's one way of doing it. Another way would be to subtract 3 days from the appointment day.
todayRowIdx = (datetime(c(:,2)) - days(3)) == datestr(floor(now));
% Or
todayRowIdx = datetime(c(:,2)) == (datestr(floor(now)) + days(3));
Sue MM
Sue MM 2019 年 7 月 22 日
Amazing, I’ll give this a try thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeHistorical Contests についてさらに検索

質問済み:

2019 年 7 月 22 日

コメント済み:

2019 年 7 月 22 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by