Jump to content
Sign in to follow this  
redder

Run standard email client with special characters in body

Recommended Posts

redder

Hello!

I want to run the standard email client with a predefined body. In this body are several special characters.

(I use Weswolf's "_INetMail()" function)

However my problem is, that in the email client everything after the ampersand ("&") is not beeing copied.

I had the same problem in basic. There I had to replace the special character with it's HEX-code. In AutoIT this doesn't work - there you only get the HEX-codes in the standard email client not the real characters. Does anyone know why?

Thanks in advance, sorry for my substandard English :) and best regards!

redder

Edited by redder

Share this post


Link to post
Share on other sites
KaFu

Upsa #2 :).... In fact the _INetExplorerCapable() is part of _INetMail() and seemed to be the problem!.... hmmm, this tweaked function works with Lotus Notes at least, but you might run into other problems due to the now missing IE compliance check...

#include <INet.au3>

;$Address = InputBox('Address', 'Enter the E-Mail address to send message to')
;$Subject = InputBox('Subject', 'Enter a subject for the E-Mail')
;$Body = InputBox('Body', 'Enter the body (message) of the E-Mail')

$Address = "test@test.com"
$Subject ="äää?üü?üß"
$Body = "tes?tää=ääüüü"

$Subject = StringReplace($Subject,'&','%26')
$Subject = StringReplace($Subject,'?','%3F')
$Body = StringReplace($Body,'&','%26')
$Body = StringReplace($Body,'?','%3F')


MsgBox(0,"",$address & @crlf & $subject & @crlf & $body)

MsgBox(0,'E-Mail has been opened','The E-Mail has been opened and process identifier for the E-Mail client is ' & _INetMail2($address, $subject, $body))

Func _INetMail2($s_MailTo, $s_MailSubject, $s_MailBody)
    Local $prev = opt("ExpandEnvStrings", 1)
    Local $var = RegRead('HKCR\mailto\shell\open\command', "")
    Local $ret = Run(StringReplace($var, '%1', 'mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody))
    Local $nError = @error, $nExtended = @extended
    opt("ExpandEnvStrings", $prev)
    Return SetError($nError, $nExtended, $ret)
EndFunc   ;==>_INetMail

#cs
Func _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
    Local $prev = opt("ExpandEnvStrings", 1)
    Local $var = RegRead('HKCR\mailto\shell\open\command', "")
    Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody)))
    Local $nError = @error, $nExtended = @extended
    opt("ExpandEnvStrings", $prev)
    Return SetError($nError, $nExtended, $ret)
EndFunc   ;==>_INetMail
#ce

Share this post


Link to post
Share on other sites
redder

At first thanks for your effort!

This is my solution for the problem (instead of including "Inet.au3" I copied parts of it and modified it):

Func _INetExplorerCapable($s_IEString)
        Return $s_IEString
EndFunc   ;==>_INetExplorerCapable
    
Func specialchars($string)
    $string = StringReplace($string, "%", "%25", 0, 0)
    $string = StringReplace($string, "&", "%26", 0, 0)
    $string = StringReplace($string, "!", "%21", 0, 0)
    $string = StringReplace($string, "#", "%23", 0, 0)
    $string = StringReplace($string, "*", "%2A", 0, 0)
    $string = StringReplace($string, "/", "%2F", 0, 0)
    $string = StringReplace($string, "?", "%3F", 0, 0)
    $string = StringReplace($string, "ß", "%DF", 0, 0)
    $string = StringReplace($string, "§", "%A7", 0, 0)
    $string = StringReplace($string, '"', "%22", 0, 0)
    $string = StringReplace($string, "$", "%24", 0, 0)
    $string = StringReplace($string, @CRLF, "%0A", 0, 0)
        Return $string
EndFunc

Func _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
    $s_MailBody = specialchars($s_MailBody)
    Local $prev = opt("ExpandEnvStrings", 1)
    Local $var = RegRead('HKCR\mailto\shell\open\command', "")
    Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo & '?subject=' & $s_MailSubject & '&body=' & $s_MailBody)))
    Local $nError = @error, $nExtended = @extended
    opt("ExpandEnvStrings", $prev)
    Return SetError($nError, $nExtended, $ret)
EndFunc

(It's a dirty way, but it works with my tool :) )

By the way, KaFu what do you mean with "you might run into other problems due to the now missing IE compliance check"?

Share this post


Link to post
Share on other sites
KaFu

Func _INetExplorerCapable($s_IEString)
        Return $s_IEString
EndFunc   ;==>_INetExplorerCapable
You can just leave this function away, as it does nothing :) ...

By the way, KaFu what do you mean with "you might run into other problems due to the now missing IE compliance check"?

Meant the other StringReplace() you did, I did only two... hopefully that's all there is to replace, that's what I meant with "other" problems....

Regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×