1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to pass URL to sendmail?

Discussion in 'Support' started by Mordachai, Oct 13, 2016.

  1. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    I desperately would like to pass a URL that contains spaces as part of the body of a sendmail from BTM files.

    I have tried a bunch of solutions - including trying to convert the spaces to %20 sequences.

    However, although I can get syntax to work on the command line, in a batch file it still ends up broken.

    so in this:

    %@replace[ ,^%@char[37 37]20,%OfficialMediaFolder]

    Which works on the command line - and generates a replacement of ' ' -> %20 of the contents of %OfficialMediaFolder, when executed in my batch, instead I have all spaces replaced with nothing.

    So "\\Media Server" becomes "\\MediaServer"

    This is way wrong. :(

    %@char[37] fails.
    Escaping it as shown in my @replace function fails.

    If I could output the url in a format that Outlook would consume from sendmail with spaces in it - that would be fine too!

    But I cannot figure out how to encode the URL in plaintext for sendmail so that it comes into outlook as a URL (containing spaces)....

    Help?!!!
     
  2. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Try doubling the % characters. The BTM might be trying to turn what follows into a variable. %% would escape into %.
     
  3. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Just read this part. Since you're trying to get it to show up in Outlook and if you are sending the message as "HTML format" from your sendmail, try wrapping your url like this (using html markup to force it).
    Code:
     <a href="http://some.url.com/this is the url">http://some.url.com/this is the url</a> 
     
  4. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    Thanks - that's probably useful.
    I was doubling up the % chars - that's what the @char[37 37] was intended to do - %% - but it still gets eliminated?!
    your <a href... is exactly what I want - but do I need to include some sort of header in the sendmail body to indicate that the email is in HTML format?
     
  5. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    I use a perl script for my sendmail called "sendEmail.pl". It is MUCH friendlier than sendmail. Let me look at sendmail and see what I can find out real quick.

    Edit: From the TCMD manual...
    Code:
    sendmail /h"Content-Type: text/html" ...
     
  6. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    also - how to avoid the < > being picked up as pipe / i/o symbols...
     
  7. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    ah - perl - d'oh - never considered going out to another scripting language. Yeah, ... that makes sense!
     
  8. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Just tried it. Looks like you'd need to do 4 of them.
    Code:
    13:18:19 $ echo %@char[37 37 37 37]
    %%
     
  9. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    You could try stashing your message in an external file and then grabbing it like this, but I don't know if it would be parsed any differently...
    Code:
    sendmail abc@xyz.com Party @c:\messages\invitation.txt
    Edit: This worked and the url came thru using the "<a href..." inside the text file.
    Code:
    SENDMAIL /H"Content-Type: text/html" email@address.com "Test subject" @test.txt
     
    #9 JohnQSmith, Oct 13, 2016
    Last edited: Oct 13, 2016
  10. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    You could also use here-document redirection. Took me a bit to figure out how to get it into sendmail (you can't redirect straight, you have to use the @CON:), but here it is.
    Code:
    sendmail /H"Content-Type: text/html" email@address.com "Test subject" @CON: << "MSGTXT"
    <a href="http://some.url.com/this is a test">http://some.url.com/this is a test</a>
    MSGTXT
    
    Take the quotes off from around the MSGTXT at the end of the first line if you want to allow for variable expansion.
    Code:
    set theurl=http://some.url.com/this is a test
    sendmail /H"Content-Type: text/html" email@address.com "Test subject" @CON: << MSGTXT
    <a href="%theurl%">%theurl%</a>
    MSGTXT
    
    These are lines right out of a BTM file (with the email address obfuscated).
     
  11. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    That looks like just the ticket!
    Thank you!!!
     

Share This Page