The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> I need just a little help with formating the date
Fatfenders
post Jan 31 2025, 07:36 PM
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.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 3 2025, 07:14 AM
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Loren075Keyser
post Feb 10 2025, 02:00 AM
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
5 User(s) are reading this topic (5 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th February 2025 - 06:53 PM