Jump to content

Recommended Posts

Posted

Really! Wow, maybe I do let me mess with my firewall and see what I can do. Thanks though, I will post back with results later.

Posted (edited)

Will do Aassdd! I'm trying a few different things now. I will post back once I get it to work.

Edited by StAbb
Posted

I got it to work! I used this test email and test password! And it works perfectly! Thanks man!

#Include<file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$s_SmtpServer = "smtp.gmail.com"             ; address for the smtp-server to use - REQUIRED
$s_FromName = "Test"                     ; name from who the email was sent
$s_FromAddress = "autoittest1@gmail.com";  address from where the mail should come
$s_ToAddress = "YOUR EMAIL"  ; destination address of the email - REQUIRED
$s_Subject = "Test"               ; subject from the email - can be anything you want it to be
$as_Body = "This is a test email"                           ; 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_CcAddress = ""     ; address for cc - leave blank if not needed
$s_BccAddress = ""  ; address for bcc - leave blank if not needed
$s_Username = "autoittest1"                ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$s_Password = "autoit123"                ; 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                              ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$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)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Rc:" & $rc)
EndIf
;

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
EndFunc;==>_INetSmtpMailCom
;
;
; Com Error Handler
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
  • 2 weeks later...
Posted

Is there any chance to get this work without setting the username and password?

I want to send an email from my account on yahoo.com, to my account on gmail.com, here is what i trying:

Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;##################################
; Include
;##################################
#Include <File.au3>

;##################################
; Variables
;##################################
$s_SmtpServer = "smtp.mail.yahoo.com"       ; address for the smtp-server to use - REQUIRED
$s_FromName = "Test"                        ; name from who the email was sent
$s_FromAddress = "MyAccount@yahoo.com"      ; address from where the mail should come
$s_ToAddress = "MyAccount@gmail.com"        ; destination address of the email - REQUIRED
$s_Subject = "Test"                         ; subject from the email - can be anything you want it to be
$as_Body = "This is a test email"           ; 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_CcAddress = ""                           ; address for cc - leave blank if not needed
$s_BccAddress = ""                          ; address for bcc - leave blank if not needed
$s_Username = ""                 ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$s_Password = ""                 ; 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                        ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS



$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)

If @error Then MsgBox(0, "Error sending message", "Error code: " & @error & "  Rc: " & $rc)


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
EndFunc

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    
    Return SetError(1); something to check for when this function returns
EndFunc

But i get error:

  Quote

Error code: 2 Rc: Unable to send message to SMTP-server. Trasnport error code: 0x80040217. Server response: not available

(free translation from russian muttley ).

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • Developers
Posted

Just use the Users own email capabilities and use the _INetMail() UDF.

You will not find many open smtp servers because nobody wants to be listed as a mass spammer. (only forum members are)

Jos

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.
  :)

Posted

  Quote

Just use the Users own email capabilities and use the _INetMail() UDF.

But what if user have gmail accont, he will have to set password... not safe (from his point of view)...

P.S

Oops, i deleted the second (double) post, and it seems that you deleted the other (first) one muttley

Here is the copy of it:

  Quote

And what about from Gmail? or it requires username/password anyway?

Then what mail service do you recomend to use for this task? basically i need to make some sort of "interface form" in my app, so the user will be able to send me a feedback/bug report etc. to my email (on gmail), but i don't like the idea of keeping password in the script (i have another account on gmail), and i don't like the idea of crypting every time my script as well :( - any ideas on how i can do it safer, without using (set) password?

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • Developers
Posted (edited)

I haven't deleted any of your double posts. Must have been somebody else. muttley

I do not understand your question about the users own GMail account. This UDF will start Outlook or Outlook express (or whatever is listed as the PC's mail client). I cannot see how you would easily created a Mail-me-back facility supporting all kinds of possible EMail options in a different way.

Jos

Edited by Jos

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.
  :)

Posted

  Quote

I haven't deleted any of your double posts. Must have been somebody else.

Oh ok, sorry then.

  Quote

I do not understand your question about the users own GMail account. This UDF will start Outlook or Outlook express

I see now what you mean, but i don't want to use default mail client (btw, ShellExecute("mailto:...") is almoust the same muttley ), i would like to use my own mail form (in the matter of fact i already have a GUI form to send mail, the problem is that this involves input of password/user name :) ).

But thank you anyway.... i will keep looking for a reasonable solution here...

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • 2 weeks later...
  • Developers
Posted

  yehia said:

i have same problem as all

Error code:2 Rc:The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

for all the guyz who got it to work can u help me

was it ur firewall?

It normally means that you cannot connect to the SMTP server. Maybe you can give more details about what your are exactly doing.

Jos

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.
  :)

Posted

Excuse me the dumb question ... i see many pieces of code for this topic ... which one should i start with to make my first experiments ? no "official" or "up to date" link

Thanks in advance...

  • Developers
Posted

  snaileater said:

Excuse me the dumb question ... i see many pieces of code for this topic ... which one should i start with to make my first experiments ? no "official" or "up to date" link

Thanks in advance...

The very first post in this topic in my most up-to-date example.. :P

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.
  :)

  • 4 weeks later...
Posted

hey JOS was using xprotec; and was getting this error:

'This Program has been interupted by a Fatal COM Error"

in the .au3 this is what i have changed

Global $smtpserver = "smtp.googlemail.com"
Global $sendusername = "username"
Global $sendpassword = "mypass"

Any help appreciated

  • Developers
Posted (edited)

  Donace said:

hey JOS was using xprotec; and was getting this error:

'This Program has been interupted by a Fatal COM Error"

in the .au3 this is what i have changed

Global $smtpserver = "smtp.googlemail.com"
Global $sendusername = "username"
Global $sendpassword = "mypass"

Any help appreciated

Yes, saw you posting that, so why are you also posting here?

When you look at the first post in this thread you see how to use a Com Error Event handler, but other that that I don't know what was used in the xprotec UDF.

Jos

Edited by Jos

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.
  :)

Posted

i posted here because valuator said to ;)

I dug into the udf; but I have...3 days experience with autoit was was confused; ill look into it a bit more

  • Developers
Posted (edited)

  Donace said:

i posted here because valuator said to ;)

I dug into the udf; but I have...3 days experience with autoit was was confused; ill look into it a bit more

Look at the example in the first post.

This portion will ensure more info is given about your problem:

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
....
; Com Error Handler
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
Edited by Jos

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.
  :)

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
  • Recently Browsing   0 members

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