I got it to work,

Turns out that angle brackets must be added in the Content-ID header for this to work in Gmail.

do part.Headers.SetAt("<id1>","Content-ID")

It's mentioned in this article , remark by masoudmanson.

https://stackoverflow.com/questions/41946783/gmail-blocking-small-embedd...

Thanks for helping me solve this problem! I appreciate it very much.

Hi,

I took the code from the article, still the same problem.. in Outlook I get a nice embedded pic,

In Gmail- the pic is attached.   

It seems there is a specific problem with Gmail displaying embedded images.

Did you manage to get a mail with embedded image to display correctly in Gmail?

I also tried the base64 method, and that also worked correctly only when the mail was opened in Outlook.

Method 1:

Set tmpEmail=##class(%Net.SMTP).%New()
  Set tmpEmail.smtpserver="xyz"
  Set msg=##class(%Net.MailMessage).%New()
  Set msg.From="from.."
  Set msg.Charset="Windows-1255"
  D msg.To.Insert("to..")
  Set msg.Subject="testing"
  set msg.IsHTML=1   
  set msg.MultiPartType="related"   
  do msg.AttachFile("c:\xyzxyz\","a.png")
  set part=msg.Parts.GetAt(1)
  set part.ContentType="image/png"
  set part.InlineAttachment=1 // otherwise, the default is attachment. graphic inside html
  do part.Headers.SetAt("id1","Content-ID")   
  do msg.TextData.Write("<b>Hello< / b>, </b><font color='red'>World<font color='red'></font>!")
  do msg.TextData.Write("<br/><img src='cid:id1'>")
  s status= tmpEmail.Send(msg)
 

Method 2 base64

  Set tmpEmail=##class(%Net.SMTP).%New()
  Set tmpEmail.smtpserver="xyz"
  Set msg=##class(%Net.MailMessage).%New()
  Set msg.From="from.."
  Set msg.Charset="Windows-1255"
  D msg.To.Insert("to..")
  Set msg.Subject="testing base64"
  set msg.IsHTML=1   
  set msg.MultiPartType="related"
  set stream=##class(%GlobalBinaryStream).%New()
  do stream.Write($system.Encryption.Base64Decode("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAADUUlEQVR42lWTWUwTURSGaUtIKY5QweISTUzceDGu0Rj1xURjTNQEE+ODGn0hPhBEQdqZztahBbrAtFih1Fprh9IBiVLLErZSU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1")
    
  set part=msg.Parts.GetAt(1)
  set part.ContentType="image/png"
  set part.InlineAttachment=1    // otherwise, the default is attachment. graphic inside html
  do part.Headers.SetAt("id1","Content-ID")

  do msg.TextData.Write("<b>Hello< / b>, </b><font color='red'>World<font color='red'></font>!")
  do msg.TextData.Write("<br/><img src='cid:id1'>")
  s status= tmpEmail.Send(msg)

Hi,

Ok. here is the code, it's a minimal code of a many to many relationship:

Class TafnitTest.Student Extends (%Persistent, %JSON.Adaptor, %Populate)
{
Property MyName As %String;
Relationship Teachers As TafnitTest.TechersToStudents [ Cardinality = many, Inverse = Student ];
}
 

Class TafnitTest.Teacher Extends (%Persistent, %JSON.Adaptor, %Populate)
{

Property MyName As %String;

Relationship Students As TafnitTest.TechersToStudents [ Cardinality = many, Inverse = Tracher ];

}

Class TafnitTest.TechersToStudents Extends (%Persistent, %JSON.Adaptor, %Populate)
{

Relationship Student As TafnitTest.Student [ Cardinality = one, Inverse = Teachers ];

Index StudentIndex On Student;

Relationship Tracher As TafnitTest.Teacher [ Cardinality = one, Inverse = Students ];

Index TracherIndex On Tracher;

}

Also I will attach the code as an XML export for convenience of importing and testing, If I find a way to do upload a file here..

after creating the classes, populate:

W ##CLASS(TafnitTest.Teacher).Populate(100)
W ##CLASS(TafnitTest.Student).Populate(100)
W ##CLASS(TafnitTest.TeachersToStudents).Populate(100)
 

And the JSON Export:

d ##CLASS(TafnitTest.Student).%OpenId(1).%JSONExport()
{"MyName":"O3183","Teachers":[{},{}]}
 

The JSON indicated that two teachers  teach this student, but not the details.

In my post, the id is a property I added to the intermediate class. I did not add it in this minimal example.

Thanks!

Nael Naseraldeen

Hi,

Thank you,

That would work if the caller is nice enough to set the second variable to null before calling the function. 

But he may not do it..

So if the function is:

MyFunc(Param1,Param2)

    if $d(Param2) {
    Answer= " 2 params"
    Else {
    Answer= " 1 params"
    }
  
    Param2="it's all good"

   Answer

Then:

USER>w $$MyFunc^%ZWBNAEL(1)
 1 params
USER>w $$MyFunc^%ZWBNAEL(1,.V)
 1 params

Hi,

This is a very usefull article, thank you!

But it seems strange that Cache does not support exporting  classes to JSON in a native way.

We can use  %ZEN.Auxiliary.altJSONProvider , but for some reason, %Date properties are not handled

correctly - they are not converted to ODBC format. at least in Cache 2016.2

is this issue fixed in later Cache Versions?

Thanks,

Nael