[Event] Send email at specific time each day with photo attached

minth1

n3wb
Joined
Oct 19, 2023
Messages
1
Reaction score
0
Location
USA
I've figured out how to send motion events with photo via email and tested the email configuration settings. But I'm not seeing an option to achieve what I'm wanting. I would like 5 cameras attached to the NVR, to send a photo via email at 11:00pm every day. One post I found elsewhere said to use the "alarm input" event function. They recommended setting alarm input to NC and schedule for 1 minute interval around 11:00pm Below is the settings I'm using but not able to trigger the email with them.

  • DS-2CD2165G0-I
    • firmware V5.6.2 build 190701
  • DS-2CD2683G1-IZS
    • firmware V5.6.6 build 210625
NVR:
  • DS-96128NI-I24 / H
    • V4.51.127 build 220831

2023-10-19 09_29_27-Configuration.png
 

trempa92

Pulling my weight
Joined
Mar 26, 2020
Messages
736
Reaction score
230
Location
Croatia,Zagreb
Im not sure about email, but with FTP it works.

For FTP you have Capture interval time and u set it at 11PM to trigger every 24hours. It will be uploaded to FTP server.


1697781624767.png
1697781690102.png

Or make a small service that will run somewhere on your server.


C#:
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mail;
using System.Threading.Tasks;
using System.IO;

public class CameraService
{
    private string[] cameraIps = { "192.168.1.1", "192.168.1.2" }; / Add all camera IPs here
    private const string Endpoint = "/ISAPI/Streaming/channels/101/picture";
    private const int Port = 80;
    private const string Username = "yourUsername";
    private const string Password = "yourPassword";
    private const string EmailTo = "example@email.com";

    public async Task CaptureAndSendImages()
    {
        var images = await CaptureCameraImages();

        SendEmail(images);
    }

    private async Task<byte[][]> CaptureCameraImages()
    {
        byte[][] images = new byte[cameraIps.Length][];

        for (int i = 0; i < cameraIps.Length; i++)
        {
            var url = $"http://{cameraIps[i]}:{Port}{Endpoint}";

            CredentialCache credentialCache = new CredentialCache();
            credentialCache.Add(new Uri(url), "Digest", new NetworkCredential(Username, Password));

            using var httpClientHandler = new HttpClientHandler
            {
                Credentials = credentialCache
            };

            using var httpClient = new HttpClient(httpClientHandler);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var response = await httpClient.GetAsync(url);
           
            if (response.IsSuccessStatusCode)
            {
                images[i] = await response.Content.ReadAsByteArrayAsync();
            }
            else
            {
                / Handle failure to get an image, maybe log an error or throw an exception
            }
        }

        return images;
    }

    private void SendEmail(byte[][] images)
    {
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("youremail@example.com");
        mail.To.Add(EmailTo);
        mail.Subject = "Camera Images";
        mail.Body = "Attached are the camera images.";

        for (int i = 0; i < images.Length; i++)
        {
            var stream = new MemoryStream(images[i]);
            mail.Attachments.Add(new Attachment(stream, $"camera_{i}.jpg"));
        }

        SmtpClient smtpClient = new SmtpClient("your.smtp.server");
        smtpClient.Credentials = new NetworkCredential("username", "password");
        smtpClient.Send(mail);
    }
}
Note: Here is not set to send images at exactly 11, but rather when u run app. Either make a windows Task scheduler or add method that will track time.
 
Last edited:
Top