Alarm Program-Email Pictures not working in v1.1.15, were working in v526

I had the following program working in v526 in Raspbian Stretch Mono 5.4. It now refuses to send the pictures taken by my cameras. I got this program from the previous Homegenie Forum. It refuses to compile in v1.1.15 without errors.

// when the widget button is pressed, an e-mail is sent with pictures from cameras

// This app works for the following 2 FOSCAM IP cameras:
//   FI8910W: http://<cameraID>.myfoscam.org:<port>/snapshot.cgi?user=<username>&pwd=<password>
//   FI9821W: http://<cameraID>.myfoscam.org:<port>/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=<username>&pwd=<password>&

// tried calling data from Generic IP Camera app - nothing happened (no error, nothing), although the URL
// worked fine in a browser:
//   byte[] img = Net.Webservice(http://<HG address>/api/Media.IpCamera/1/Camera.GetPicture).GetBytes();

// When I tried .WithCredentials, the e-mail was NOT sent - error message displayed.

var subject = Program.InputField("Email.Subject").Value;
var recipients = Program.InputField("Email.Recipients").Value;
var messageText = Program.InputField("Email.Message").Value;
var cameraOneImageURL = Program.InputField("IPCamera.ImageURLOne").Value;
//var cameraOneUsername = Program.InputField("IPCamera.UsernameOne").Value;
//var cameraOnePassword = Program.InputField("IPCamera.PasswordOne").Value;
var cameraTwoImageURL = Program.InputField("IPCamera.ImageURLTwo").Value;

if ((recipients != "") && (messageText != ""))
{
  Program.RunAsyncTask(() => {
    byte[] img;
    for (int x=0; x<3; x++) {
      if (cameraOneImageURL != "") {
    	img = Net.WebService(cameraOneImageURL)
//          .WithCredentials(cameraOneUsername, cameraOnePassword)
          .GetBytes();
		Net.AddAttachment( "first"+x+".jpg", img );
      }
      if (cameraTwoImageURL != "") {
	    img = Net.WebService(cameraTwoImageURL)
          .GetBytes();
		Net.AddAttachment( "second"+x+".jpg", img );
      }
   	  Pause(1);
    }
    
    if (Net.SendMessage(recipients, subject, messageText) == true)
      Program.Notify("E-Mail Pictures", "SUCCESS! Pictures sent.");
    else Program.Notify("E-Mail Pictures", "ERROR: Pictures **NOT** sent.");
  });
}
else
  Program.Notify("E-Mail Pictures", "ERROR: Missing input field(s) - recipients and/or message text.");

When I run the program the following is outputted

2018-03-15 18:47:11.9502 Trace SendMessage: getting smtpSyncLock
2018-03-15 18:47:11.9502 Trace SendMessage: got smtpSyncLock
2018-03-15 18:47:12.1062 Trace SendMessage: error sending email
2018-03-15 18:47:12.1173 Error Newtonsoft.Json.JsonSerializationException: Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'. ---> System.InvalidOperationException: Timeouts are not supported on this stream.
  at System.IO.Stream.get_ReadTimeout () [0x0000a] in <6e241547b2184f08b8370f11a198586d>:0
  at (wrapper dynamic-method) System.IO.Stream:GetReadTimeout (object)
  at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue (System.Object target) [0x0001e] in <87d97053987a40ae9d1aa30ffad1214b>:0
   --- End of inner exception stack trace ---
  at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue (System.Object target) [0x00054] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContainerContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract& memberContract, System.Object& memberValue) [0x00066] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, System.Collections.IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d6] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d4] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00095] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00269] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x0002a] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x0000e] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Newtonsoft.Json.Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Newtonsoft.Json.Formatting formatting) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at HomeGenie.Service.JsonHelper.ToPrettyJson (System.Object obj) [0x00001] in <8d43297479e340b0bc2b2a967fada7ef>:0
  at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003df] in <8d43297479e340b0bc2b2a967fada7ef>:0
2018-03-15 18:47:12.1502 Error HomeAutomation.HomeGenie.Automation      NetHelper       Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'.    Exception.StackTrace       at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue (System.Object target) [0x00054] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContainerContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract& memberContract, System.Object& memberValue) [0x00066] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, System.Collections.IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d6] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d4] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008c] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b0] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00095] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00269] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x0002a] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x0000e] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Newtonsoft.Json.Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Newtonsoft.Json.Formatting formatting) [0x00000] in <87d97053987a40ae9d1aa30ffad1214b>:0
  at HomeGenie.Service.JsonHelper.ToPrettyJson (System.Object obj) [0x00001] in <8d43297479e340b0bc2b2a967fada7ef>:0
  at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003df] in <8d43297479e340b0bc2b2a967fada7ef>:0
2018-03-15 18:47:12.1544 Trace SendMessage: disposing smtpClient
2018-03-15 18:47:12.1555 Info HomeAutomation.HomeGenie.Automation       1014   Automation Program       Program.Notification    {"Title":"E-Mail Pictures","Message":"ERROR: Pictures **NOT** sent."}

A mail is being sent with no attachments so the email sending is working fine.

Could someone running v1.1.15 try compiling this program and tell me what errors they observe

I should have mentioned that compiling this program in v1.1.15 throws up an error “Obsolete string” yet its compiles perfectly in v526.

I’m not a C# programmer but it looks like there’s something in this code that v1.1.15 does not like. The Newtonsoft JSON Serializer clearly doesn’t like something here.

Yes, the bug was related to Newtonsoft can’t serialize MemoryStream objects and those objects are used in mail attachments.

Try this HomeGenie.exe (298 KB), it should fix the errors with sending email messages.

PS. At the moment I wasn’t able to compile your automation program as my HG installation is in non-working state))

Thanks Bounz.

I’m using Raspbian so I’ll just drop that file into my HG folder and overwrite the one that’s currently there.

Any idea how this occurred between the two versions.

That sorted the problem. The program is actually working better now.

Thanks for the update

The problem has arisen because I added logging of outgoing messages (https://github.com/Bounz/HomeGenie-BE/blob/master/HomeGenie/Automation/Scripting/NetHelper.cs#L246) to troubleshoot email problems, but unfortunately, I haven’t tested it with an email with attachments…

Well it’s working fine with attachments now