Jump to content

Attaching files to "Inetmail" command


Recommended Posts

dont think u can with the built in functions _INetMail & _INetSmtpMail but i found this script done by someone (sorry cant remember who) but give this a try , works for me :D

#include <file.au3>
Global $oMyRet[2]
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 = 25, $ssl = 0)
    $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
;Authenticated SMTP
    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
;Update settings
    $objEmail.Configuration.Fields.Update
; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    Return 1
EndFunc;==>_INetSmtpMailCom
;
;
; Com Error Handler
#cs
    Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
    EndFunc;==>MyErrFunc
#ce

just save it as a UDF maybe SMTP.au3 , #include it, then use the function _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)

script to use the SMTP UDF:-

$s_SmtpServer = "smtp.gmail.com"; address for the smtp-server to use - REQUIRED
    $s_FromName = "Message from "; name from who the email was sent
    $s_FromAddress = "auto@gmail.com";  address from where the mail should come
    $s_ToAddress = "test@gmail.com"; destination address of the email - REQUIRED
    $s_Subject = "Just a quick hi"; subject from the email - can be anything you want it to be
    $as_Body = "just a quick hi, so hi how are you"; the messagebody from the mail - can be left blank but then you get a blank mail
    $s_AttachFiles = ""; the file you want to attach- leave blank if not needed;    $s_AttachFiles = $KLlimetedlocation &   $logname; the file you want to attach- leave blank if not needed
    $s_CcAddress = ""; address for cc - leave blank if not needed
    $s_BccAddress = ""; address for bcc - leave blank if not needed
    $s_Username = "anyaddress@googlemail.com"; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
    $s_Password = "passw0rd"; password for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
;$IPPort = 25; port used for sending the mail
;$ssl = 0; enables/disables secure socket layer sending - put to 1 if using httpS
    $IPPort=465; GMAIL port used for sending the mail
    $ssl=1; GMAIL
    $rc=_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)
    For $q=0 To 200
       Sleep(10)
       If $rc=1 Then ExitLoop
    Next

im sure if you search for smtp you could find the thread where this is situated and should give you more info.

This is from quite a while ago now and im not %100sure it still will work

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

  • Developers

dont think u can with the built in functions _INetMail & _INetSmtpMail but i found this script done by someone (sorry cant remember who) but give this a try , works for me :D

http://www.autoitscript.com/forum/index.ph...INetSmtpMailCom

:o

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 years later...

hi guy i read this but for me is much complicated , i have studied a alternative but dont go perfectly

first i mod. the file inet.au3 inside the include directory program , in this mode

Func _INetMail($s_MailTo, $s_bcc, $s_MailSubject, $s_MailBody ,$s_Attach)

Local $prev = Opt("ExpandEnvStrings", 1)

Local $var = RegRead('HKCRmailtoshellopencommand', "")

Local $ret = Run(StringReplace($var, '%1', _INetExplorerCapable('mailto:' & $s_MailTo &'?bcc='& $s_bcc & '&subject=' & $s_MailSubject & '&body=' & $s_MailBody & '&Attach=' & $s_Attach)))

Local $nError = @error, $nExtended = @extended

Opt("ExpandEnvStrings", $prev)

Return SetError($nError, $nExtended, $ret)

EndFunc ;==>_INetMail

after i have created a script for look if go correctly

#include <INet.au3>

global $attachment,$Address,$Subject,$Body,$bcc

$Address = 'stfn77@gmail.com';InputBox('Address', 'Enter the E-Mail address to send message to')

$Subject = 'oggetto';InputBox('Subject', 'Enter a subject for the E-Mail')

$Body = 'corpo messaggio';InputBox('Body', 'Enter the body (message) of the E-Mail')

$bcc = 'stfn77@gmail.com';InputBox('Body', ' of the E-Mail')

$Attach = "C:UsersstefanoDesktopFibromyalgia.pdf"

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

the script go and dont return error but attachment file dont attach , why ? :)(

only attch dont go ;)((

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...