cancel
Showing results for 
Search instead for 
Did you mean: 

xp_sendmail with inline attachment

dhkom
Participant
0 Kudos
565

I'm having trouble getting the following xp_sendsmtp documentation example working: 'This example uses SMTP to send inline HTML formatted message with a signature and two attachments, one of which is a ZIP file.'

The slightly modified example, with obvious placeholders, is shown below.

Suggestions or insights welcome. Thank you!


begin
  declare l_rc                  integer;
    declare s_content                           long varchar;
  --
    SET s_content = 
        'Content-Type: multipart/mixed; boundary="xxxxx";\\n' ||
        'This part of the email should not be shown.  If this ' ||
        'is shown then the email client is not MIME compatible\\n\\n' ||
        '--xxxxx\\n' ||
        'Content-Type: text/html;\\n' ||
        'Content-Disposition: inline;\\n\\n' ||
        'Plain text.' ||
        /* xp_read_file( '\\\\temp\\\\johndoe.sig.html' ) || */
        '--xxxxx\\n' ||
        'Content-Type: application/zip; name="test.zip"\\n' ||
        'Content-Transfer-Encoding: base64\\n' ||
        'Content-Disposition: attachment; filename="test.zip"\\n\\n' ||
        base64_encode( xp_read_file( 'c:\\\\temp\\\\test.zip' ) ) ||
        '\\n\\n' ||
        '--xxxxx--\\n'
    ; 
    --
    -- Port 2525 is for non-ssl email
    l_rc = call xp_startsmtp (
        smtp_sender = '(sender email)',
        smtp_server = '(mail server)',
        smtp_port = 2525,
        smtp_sender_name = 'John Doe',
        smtp_auth_username = '(sender email)',
        smtp_auth_password = '(password)'
    );
    --
  l_rc = call xp_sendmail (
        recipient = 'joe@contoso.com', 
        subject = 'Test sending email with attachment from SQL Anywhere', 
        "message" = s_content,
        content_type = 'ASIS',
        include_file = '\\\\temp\\\\bla.sql'
    );
    --
  l_rc = call xp_stopsmtp ();
end
go

View Entire Topic
dhkom
Participant
0 Kudos

I may be on to something on this:

I am testing using 16.0.0.1324. I vaguely remember experiencing a problem whereby a sent email message had an empty body. Sure enough, I found the following by searching through my documentation:

================(Build #1535 - Engineering Case #739835)================

The body of email messages sent using xp_sendmail would have been truncated 
at 255 characters. This has been fixed.

... I suspect this is what is going on here. Will investigate further and post an update.

Thanks to all, especially pcollins for code sample - which I will study.

PCollins
Participant

We are using the latest version of 17 and I'm certain it's still an issue for us - I will test again

Also the same email shows content when displayed in say GMail

VolkerBarth
Contributor
0 Kudos

Hm, if you do have to test with the long EOL'ed version 16, I would recommend to use the customer's version (hopefully the latest EBF, i.e. built 2798 on Windows/Linux) instead of the much older GA version 1324... (Note, I'm not suggesting the particular issue does behave differently with those versions... I simply don't know.)

dhkom
Participant
0 Kudos

I have now been testing in SA 17 (17.0.10.5963 - older there too), and am not having any more success. I have verified that my "usual" emails send in my SA17 whereas they did not in my long EOL'ed SA16 with the 255 character bug.

pcollins - I'm not having much success yet adapting your sample. I'm noticing, however, there are no end tags for <head> or <body>.

For the sake of expediency, I'll probably just create a file in %temp% and send it via "include_file", which does work for me.

I'd be very appreciative if someone were inclined to post an easily reproducible SQL Anywhere snippet. No worries if not convenient.

As for that obsolete SA16 version - for better or for worse, I'm nervous about mucking with my well-oiled development machine. However I am about to move to a new development machine, and I'll make sure a much more recent SA16 is up on running on that.

PCollins
Participant
0 Kudos

sorry I should have included a copy of the D:\\system-email-sig.htm, this has the closing tags in it, along with a signature html before it