![]() |
![]() ![]() |
![]() |
Fatfenders |
![]()
Post
#1
|
Group: Members Posts: 1 Joined: 31-January 25 Member No.: 29,367 ![]() |
I know precious little about html and have no need to learn much since this may be the only time I need to know how to do something. I currently would like to know how to place a date/time stamp in the body of an email.
Background: I recently decided to use a few ESP32_CAM's around my property. Using examples I found on the web (and made a few changes to) I now have everything working nicely, almost. I found an Arduino sketch that, when triggered, will take an image, attach it to an email, and send it to my email address. The only change I would still like to make is to insert a time/date stamp in the body above the image. Currently, the code: String htmlMsg = "<h2>Photo captured with ESP32-CAM and attached in this email.</h2>"; Displays in the body of the email where I would like to put a time/date stamp. I have looked at the only other place in the sketch that formats the time/date stamp but it writes it to the monitor: time_t ts = (time_t)result.timestamp; localtime_r(&ts, &dt); ESP_MAIL_PRINTF("Message No: %d\n", i + 1); ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed"); ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str()); ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str()); I don't have a clue as to how to do the same for placing it into the body of the email. |
Brian Chandler |
![]()
Post
#2
|
Jocular coder ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,489 Joined: 31-August 06 Member No.: 43 ![]() |
I don't think this has anything to do with html, which is a layout language for webpages. You will need to work out where the samples you showed came from, and ask for help there.
|
Loren075Keyser |
![]()
Post
#3
|
Group: Members Posts: 1 Joined: 10-February 25 Member No.: 29,376 ![]() |
To add a date/time stamp to your email body, use the formatted timestamp directly in your htmlMsg string. Here's a concise example:
// Format the timestamp time_t ts = (time_t)result.timestamp; struct tm dt; localtime_r(&ts, &dt); String dateTime = String(dt.tm_year + 1900) + "/" + String(dt.tm_mon + 1) + "/" + String(dt.tm_mday) + " " + String(dt.tm_hour) + ":" + String(dt.tm_min) + ":" + String(dt.tm_sec); // Update the email message String htmlMsg = "<h2>Photo captured with ESP32-CAM and attached in this email.</h2>"; htmlMsg += "<p>Date/Time: " + dateTime + "</p>"; This will insert the date/time stamp in the email body above the image. |
![]() ![]() |
![]() |
Lo-Fi Version | Time is now: 18th February 2025 - 06:55 PM |