Jump to content

How to attach file in email


Recommended Posts

Hi,

My first post here but not new to AutoIT at all, did some coding before.

I'm trying to attach a .xls file to an email sent directly from AU3 - I have sample code that uses TCPStartup() functions but can't seem to find a way to attach a file. I've checked INet functions but this doesn't seem to be helpful.

Any suggestions or I have to do external emailer?

Thanks

Edited by USBFreak
Link to comment
Share on other sites

Use CDO.Message

Dim $oMyError = ObjEvent ("AutoIt.Error", "ErrorHandler")

_SendEmail('from@who.com', 'to@somebody.com', 'copy@who.com', 'blind_copy@who.com', 'subject', 'body', @ScriptDir & "\Test.txt")

Func _SendEmail($e_From, $e_To, $e_Cc, $e_Bcc, $e_Subject, $e_Text, $e_attach = '')
    $objMessage = ObjCreate ("CDO.Message")
    If @error Then Return
;    $objMessage.BodyPart.ContentTransferEncoding = "8bit"
;    $objMessage.BodyPart.CharSet = "windows-1250"
    $objMessage.From = $e_From
    $objMessage.To = $e_To
    $objMessage.Cc = $e_Cc
    $objMessage.Bcc = $e_Bcc
    $objMessage.Subject = $e_Subject
    $objMessage.TextBody = $e_Text
    $objMessage.AddAttachment($e_attach)
    $objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = '10.10.10.200'
    $objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    $objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    $objMessage.Configuration.Fields.Update
    $objMessage.Send
EndFunc

Func ErrorHandler()
    $HexNumber = Hex($oMyError.number, 8)
    
    MsgBox(16, "CHYBA", "Při odesílání emailu došlo k chybě!" & @CRLF & @CRLF & _
            "Popis chyby: " & @TAB & $oMyError.description & @CRLF & _
            "Win. popis:" & @TAB & $oMyError.windescription & @CRLF & _
            "Číslo řádku: " & @TAB & $oMyError.scriptline & @CRLF & _
            "Číslo chyby: " & @TAB & $HexNumber & @CRLF & _
            "Objekt: " & @TAB & $oMyError.source)
    
    SetError(1)
EndFunc

Note CDO.Message is not working on Win9x systems.

For more examples search forum or see Email_zak in my signature ...

Edited by Zedna
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...