ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Including a Logo from the IFS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Including a Logo from the IFS

    My apologies if this has already been asked - I've been away from the site for a while due to lack of employment and I'm just getting back to the site now.

    I'm working on an invoicing project - I'm sending emails to the electronic customers and the body of the email is coded entirely in HTML -- I want to include the company logo and some additional verbiage and I have it defined in an HTML file. How do I code this in an RPG variable so that the program knows where to grab it and includes it. BTW - I'm using HelpSystems ESNDMAIL command and it isn't working correctly to show the logo - so I'm working on another solution myself. Any help will be greatly appreciated. Oh - and give me about ten minutes to go make sure I have my profile updated to reflect my new email address.

  • #2
    The answer to the question si going to depend entirely on the e-mail software you're using. Basically, your question is "how do I tell ESNDMAUL to create an e-mail wiht a logo embedded into it". Since I'm not familiar with ESNDMAIL, I cannot answer the question -- would suggest asking HelpSystems.

    Comment


    • #3
      Hi Scott!

      HelpSystems has been working on the resolution for three days now ... still no answer, and my apologies for not being more clear with my question. If I was just straight up writing code in a /free RPG program and creating a variable to contain my HTML code and it included an img src tag - and the image was stored in the IFS - how is it coded? I dabbled a bit yesterday and thought I was going to bring the Exchange server to its knees .. oops And each wall I encounter just puts more questions in my mind. If I'm creating an email from the IBMi and I want to include my company logo - is there a method for doing so? I want to say that .... oh about 7-8 years ago you told me that there was a way - but I no longer work for that company whose project I was working on, and I can't remember if I ever did get the logo in the email (I think we went to signatures) and I can't find my original post to this forum asking my question - years ago - hence I'm asking again. I have the sneaky suspicion that it's going to take HelpSystems a bit to figure it out and I thought maybe I could come up with a different way of doing the same thing.

      I have to stay with HelpSystems ESEND tool for emailing so if I can figure out another way for it to work - well then I'm golden.

      Regards
      R

      Comment


      • #4
        E-mail messages that contain content like images and HTML are coded in a format known as MIME (Multipurpose Internet Mail Extensions). You see, basic e-mail messages (that the internet standards are built around) are just simple ASCII text files, and the protocols for transferring email messages over the Internet will not work properly if the messages aren't just simple plain text. So how do you include things like images, attachments, HTML/Colors/Fonts, etc? A special encoding is necessary to include all of these things, but still have them be processed as simple/plain ASCII text files. That's what MIME is all about.

        So a basic/plain E-mail message looks something like this:

        Code:
        From: Scott Klement <user@host.com>
        To: NYCountryGal <you@there.com>
        Subject: Subject Line Goes Here
        Date: (whatever)
        
        Message message message message
        The idea is that everthing before the first blank line in an e-mail message are keywords with values. The keyword goes before the colon (in this example, the keywords are From, To, Subject and Date) and everything after the colon is the value of that keyword. Each line of text is terminated with a carriage return / line feed sequence. (CRLF).

        Everything after the first blank line is the message body -- i.e. the text that's shown to the user.

        This basic plain text format is very simple, but lacks the ability to do graphics, attachments, html, etc. But, all e-mail software must send messages that fit in this format. MIME allows messages to be divided into "parts", and each part can have its own keywords, and the different parts can be encoded different ways to allow non-text formats to be included in a text message. So taht is what MIME does, it allows you to do more with your e-mail message than just plain text.

        For example:
        Code:
        From: Scott Klement <user@host.com>
        To: NYCountryGal <you@there.com>
        Subject: Subject Line Goes Here
        Date: (whatever)
        MIME-Version: 1.0
        Content-Type: multipart/related; boundary="--=_ScottsBoundaryThatHeMadeUp"
        
        Hi! You will only see this part of the message if your e-mail reader doesn't
        support MIME.  So almost nobody will ever see this!
        
        ----=_ScottsBoundaryThatHeMadeUp
        Content-type: text/html
        
        <html>
           <p>This is text in an e-mail message that is HTML</p>
           <img src="http://example.com/image.jpg"></img>
        </html>
        
        ----=_ScottsBoundaryThatHeMadeUp--
        With MIME, you can hopefully see, there are some new keywords. MIME-Version tells the mail reader that you are using MIME format. The Content-Type tells the mail reader what type of content to expect, in this case "multipart/related" means that the e-mail is divided into multiple parts that are related to each other. (There are many other types.) The boundary string will be used to divide these parts up, and should be a string that is unlikely to appear naturally in the mesage.

        The first "part" (division) of the e-mail message starts when it finds a boundary string that is preceded by two dashes (the "--" characters). So if the boundary string is "--=_ScottsBoundaryThatHeMadeUp" then the first part begins when "----=_ScottsBoundaryThatHeMadeUp" is found. (Notice the extra two dashes at the start). Each part has it's own keywords immediately after the boundary, and the first blank line after the boundary signals the end of the keywords, and the start of the data. the "Content-Type" keyword in the first part, here is "text/html" meaning that this part of the e-mail message is an HTML message.

        You can have as many parts as you like. Each part starts with the boundary string with the two dashes. The entire multipart/related message ends when a boundary string is found that has two dashes both before and after it. So the "----=_ScottsBoundaryThatHeMadeUp--" string after the HTML document signals the end of the whole message.

        In this case, I have only one part, and it is an HTML message. The HTML message has an image in it -- but the image is not kept inide the HTML, it is a link to a web page. Most mail readers will not show these images by default, but instead will show the message without the images and ask the user if he/she wants to download the images. (Or require them to add the user to their address book before it will download the images, or something similar to that.)

        To avoid that, you need to create a second part that contains the actual image... that way it can be included in the message itself. Since an image is NOT text, it has to be base64-encoded, which basically is a way of encoding binary data so that it is represented entirely by text characters. The mail software will need to know that it is base64-encoded, so there is an additional keyword to tell it that (content-transfer-encoding). We'll also need a way to tell it to show the image in the message (as opposed to making it an attachment) so there is a keyword for that (content-disposition) and the HTML will need some sort of way to refer to the image since we don't want a URL that points to a separate server, and so we'll need a keyword for that (Content-id).

        The result would look something like this:

        Code:
        From: Scott Klement <user@host.com>
        To: NYCountryGal <you@there.com>
        Subject: Subject Line Goes Here
        Date: (whatever)
        MIME-Version: 1.0
        Content-Type: multipart/related; boundary="--=_ScottsBoundaryThatHeMadeUp"
        
        Hi! You will only see this part of the message if your e-mail reader doesn't
        support MIME.  So almost nobody will ever see this!
        
        ----=_ScottsBoundaryThatHeMadeUp
        Content-type: text/html
        
        <html>
           <p>This is text in an e-mail message that is HTML</p>
           <img src="cid:sklogo.gif"></img>
        </html>
        
        ----=_ScottsBoundaryThatHeMadeUp
        Content-type: image/gif; name="sklogo.gif"
        Content-Transfer-Encoding: base64
        Content-ID: <sklogo.gif>
        Content-Disposition: inline; filename="sklogo.gif"
        
        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
        
        ----=_ScottsBoundaryThatHeMadeUp--
        So the HTML now refers to the image using "cid:" (signalling a content id) which tells the e-mail reader that the image is in the same message. The next part contains the image, which in this example is a GIF image (so image/gif is the content type). The name= and filename= probably aren't needed -- but e-mail readers use these if the user chooses not to show the image, and when you choose to save the image from the e-mail somewhere, etc. It uses them to choose the default filename, etc. The Content-Id is the important part, that is the filename that the cid: refers to.

        So that is the format of the e-mail message you'd need to create if you want to build this from the ground up. You can write that to a file in the IFS using the standard IFS APIs (make sure you write it in ASCII, as e-mail software does not support EBCDIC, and even Unicode can be a problem, so Unicode should really be encoded into a format that works with 7-bit ASCII).

        Once you've done that, you'll just have an e-mail file on disk, of course. (Though, if you make the extension something like ".eml" a windows program like Outlook will read it if you double click it, which can be useful for testing your format.)

        Then you also need a way to send it... the Internet standard for that is SMTP. IBM does provide an API for sending SMTP messages, but it is not very good, and the better E-mail software will provide it's own SMTP client along with the ability to connect directly to your Exchange or smother SMTP server (like Postfix, etc.)

        Sorry, but i simply can't explain all of this stuff in a forum post. I think I'm already stretching the limits on what makes sense to post in the forum!

        I have written articles on this stuff (more than 10 years ago now) that you could refer to. One on formatting messages in MIME:
        Read through for news and resources on software development topics, including low-code-no-code, serverless computing and programming languages.


        And one on SMTP:
        Read through for news and resources on software development topics, including low-code-no-code, serverless computing and programming languages.


        Unfortunately, these articles are so screwed up by the site not formatting things properly, losing the code downloads, etc, that it's hard to recommend them anymore. But, you can try (using the "printable" format might be easier to read). The sample code is available here:



        So... I hope that this is useful to you. But, what always seems to happen is that I explain all of this (this message took more than an hour for me to write) and then people look at it and say "that's too much, I'll just use a utility that does the work for me".

        Comment


        • #5
          One more thing... the date keyword should be formatted like this:
          Code:
          Date: 21 Apr 2017 17:40:01 -0500
          It should always have that format with the day number, then month abbreviation, year, time in 24-hour format, and time zone. The time zone is listed as an offset from UTC, so -0500 means 5 hours and zero minutes earlier than UTC (which would be correct for Central Daylight Time, or Eastern Standard Time, etc).

          Comment


          • #6
            Thank you ... I really do appreciate the time you put into writing this. You always give a good explanation and are very helpful with your answers, and you are correct - you went through this detailed explanation and I won't be using it - right now. There are some other projects that it will come in very useful for - but HelpSystems got back to me on my issue --- rather humorous ... it is working -- just not with Outlook. When the senior tech tested the issue and sent the file to Yahoo - the logo came through with no issues - when opened in Outlook - it removes the logo (for whatever reason and provides no link to click on ) Your effort was not wasted - I promise. And thank you again...

            Comment

            Working...
            X