Code : Tout sélectionner
#AutoIt3Wrapper_Run_AU3Check=n ;syntaxcheck désactivé plus de probleme avec "to"
$file = FileOpenDialog("Fichier à convertir", @DesktopDir, "All images (*.*)")
If @error Then Exit
$f = FileOpen($file, 16)
$t = FileRead($f)
FileClose($f)
$t = _Base64Encode($t)
Global $as_Body = '<HTML>' & @CRLF
$as_Body &= '<body>' & @CRLF
$as_Body &= '<img style="width: 200px; height: 200px;" alt="Embedded Image" src="data:image/png;base64,' & $t & '">' & @CRLF
$as_Body &= '<font color="yellow">' & @CRLF
$as_Body &= 'Hello World' & @CRLF
$as_Body &= '</font>' & @CRLF
$as_Body &= '</body></HTML>'
Func _Base64Encode($input)
$input = Binary($input)
Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]")
DllStructSetData($struct, 1, $input)
Local $strc = DllStructCreate("int")
Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($struct), _
"int", DllStructGetSize($struct), _
"int", 1, _
"ptr", 0, _
"ptr", DllStructGetPtr($strc))
If @error Or Not $a_Call[0] Then
Return SetError(1, 0, "") ; error calculating the length of the buffer needed
EndIf
Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]")
$a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($struct), _
"int", DllStructGetSize($struct), _
"int", 1, _
"ptr", DllStructGetPtr($a), _
"ptr", DllStructGetPtr($strc))
If @error Or Not $a_Call[0] Then
Return SetError(2, 0, ""); error encoding
EndIf
Return DllStructGetData($a, 1)
EndFunc ;==>_Base64Encode
;====================================================== Envoi Mail Confirm =======================================================
SendMail("sujet",$as_Body,0)
Func SendMail($s_Subject,$as_Body,$s_AttachFiles)
$s_SmtpServer = "smtp.orange.fr"
$s_FromName = "tonton"
$s_FromAddress = "tonton@autoit.fr"
$s_ToAddress = "tonton@autoit.fr"
$s_CcAddress = ""
$s_BccAddress = ""
$s_Username = "tonton@autoit.fr"
$s_Password = "password"
$IPPort = 25
$ssl = 0
$mail=""
$mail= INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username ="", $s_Password="",$IPPort, $ssl)
EndFunc
Func INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject , $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password ,$IPPort, $ssl)
$objEmail = ObjCreate("CDO.Message")
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
$objEmail.HTMLBody = $as_Body
Else
$objEmail.Textbody = $as_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
For $x = 1 To $S_Files2Attach[0]
;$S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment ($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
SetError(1)
return 0
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $Ssl Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
$objEmail.Configuration.Fields.Update
$objEmail.Send
if @error then
SetError(2)
return
EndIf
EndFunc
Func MyErrFunc()
Return
EndFunc