Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[AutoIt]SMTP mail function with multi-attachment support filter_list
Author
Message
RE: [AutoIt]SMTP mail function with multi-attachment support #11
(04-01-2013, 07:19 AM)thebarcode Wrote: Can you post a working sample script with GUI? You only posted a function...

Well jeez, asking for the spoonfeeding are we? :nono: If you don't know how to create a GUI when the meat of the script has already been written for you then you shouldn't be "programming" in the first place. It means you're just a skid, and you leach others work.

This is an old thread anyways, I don't know why you bumped it just to ask for him to code your project for you.

On topic though, instead of all the function calls to Chr(), can't you do this in AutoIt?
Code:
$myMail = ObjCreate("CDO.Message")

Instead of:
Code:
$myMail = ObjCreate(Chr(67)&Chr(68)&Chr(79)&Chr(46)&Chr(77)&Chr(101)&Chr(115)&Chr(115)&Chr(97)&Chr(103)&Chr(101))

I don't understand why you have so many perhaps unnecessary Chr() calls... I also think it would be better to prevent the rest of the mail initialization from executing if an error is present, rather than just the send function to prevent the message which had already been initialized, from being sent.

Something like this?
Code:
Func _CompSMTPmail($Username,$Password,$From,$To,$Subject,$Body,$smtp,$port,$attachme​nts=Chr(0))
    Global $ERR
    If Not StringLen($Username) > 1 Or $Username=Chr(0) Then
        $ERR = 1
    ElseIf Not StringLen($Password) > 1 Or $Password=Chr(0) Then
        $ERR = 2
    ElseIf Not StringLen($From) > 1 Or Not StringInStr($From,"@" Or $From=Chr(0) Then
        $ERR = 3
    ElseIf Not StringLen($To) > 1 Or Not StringInStr($To,"@") Or $To=Chr(0) Then
        $ERR = 4
    ElseIf Not StringLen($Subject) > 1 Or $Subject=Chr(0) Then
        $ERR = 5
    ElseIf Not StringLen($Body) > 1 Or $Body=Chr(0) Then
        $ERR = 6
    ElseIf Not StringLen($smtp) > 1 Or $smtp=Chr(0) Then
        $ERR = 7
    ElseIf Not $port > 0 Then
        $ERR = 8
    EndIf
    If Not $ERR Then
        $myMail = ObjCreate("CDO.Message")
        $myMail.Subject=$Subject
        $myMail.From=$From
        $myMail.To=$To
        If StringInStr($Body,"<" And StringInStr($Body,">") Then
            $myMail.HTMLBody=$Body
        Else
            $myMail.TextBody=$Body
        EndIf
        If StringLen($attachments) > 1 Then
            Dim $attc = StringSplit($attachments,";")
                If IsArray($attc) Then
                    For $i = 1 To $attc[0]
                        If FileExists($attc[$i]) Then $myMail.AddAttachment($attc[$i])
                    Next
                EndIf
        EndIf

        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")=$smtp
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=$port
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $Username
        $myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $Password
        $myMail.Configuration.Fields.Update
        $myMail.Send
    EndIf
    SetError($ERR)
EndFunc

I'm not an AutoIt programmer, but this is just speculation. I also think that having to set the error more than once for every possible error condition is not very optimized. I'd have to look into the SetError() function, but if it doesn't need to be set if there is no respective error to report, then you should check if the error is the equivilant of ERROR_SUCCESS before calling that. Right now, you could end up setting $ERR more than once, and the last error to be set would be called with SetError(). In my opinion, if an error condition is found, $ERR should only be set once, being the first error condition found...
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [AutoIt]SMTP mail function with multi-attachment support #12
Hello...

I know how to create form by using Koda. Anyways, just asking.

Reply

RE: [AutoIt]SMTP mail function with multi-attachment support #13
(04-03-2013, 04:27 AM)thebarcode Wrote: Hello...

I know how to create form by using Koda. Anyways, just asking.

AutoIt provides you with examples on how to create GUI's after it is installed. You shouldn't need Koda to know how in my opinion.

:ok:
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: [AutoIt]SMTP mail function with multi-attachment support #14
But Koda defines it. Well, it is your opinion and we do have different approach. Thanks dude!

Reply

RE: [AutoIt]SMTP mail function with multi-attachment support #15
(04-03-2013, 09:11 AM)thebarcode Wrote: But Koda defines it. Well, it is your opinion and we do have different approach. Thanks dude!

Koda automates what you can do manually... Nothing more. There's AutoIt examples for a full range of controls I believe, last time I took a look at AutoIt. I don't have it right now though.

About no more difficult than creating a GUI in Powershell.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: 1 Guest(s)