Sign in to follow this  
Followers 0
rage

SMTP Trouble

13 posts in this topic

#1 ·  Posted (edited)

Hello all,

I'm having trouble sending an email via SMTP. I have searched the forum, read the posts, used the helpfile, downloaded example files but nothing seems to be working.

Below is one of the scripts I've found but it doesn't work...

#Include<file.au3>

$s_SmtpServer = "smtp.google.com"

$s_FromName = "My Name"

$s_FromAddress = "My email@gmail.com"

$s_ToAddress = "My email@hotmail.com"

$s_Subject = "Testing"

$as_Body = "test"

$s_AttachFiles =""

$s_CcAddress = ""

$s_BccAddress = ""

$s_Username = "myemail@gmail.com"

$s_Password = "my gmail password"

$IPPort=25

$ssl=1 HAVE NO IDEA IF THIS SHOULD BE 0 OR 1 FOR GMAIL?

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

Global $oMyRet[2]

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$rc = _INetSmtpMailCom("MailServer", "Your Name", "your@Email.Address.com", "CCadress1@test.com;CCadress2@test.com", "Test Subject", "Test <b>Body</b>", "test.au3;test3.au3")

If @error then

msgbox(0,"Error sending message","Error code:" & @error & " Description:" & $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

Please help, I'm getting desperate :P.

If you could amend this code or give me a working code that would be great.

Thanks

Rage

Edited by rage

Share this post


Link to post
Share on other sites



Line 67 (File "C:\Documents and Settings\My Name\Desktop\folder\subfolder\file

$objEmail.Send

$objEmail.Send^ ERROR

Error: The requested action with this object has failed.

Forgot to add the error message.

Share this post


Link to post
Share on other sites

This is another code I have tried,

$a = "smtp.google.com"
$b = "myemail@gmail.com"
$c = "mypassword"

Emailx("myemail","myfriendwhoiamemailingto@hotmail.com","Test","Test")

Func Emailx($d, $e, $f, $g)
$h = ObjCreate ("CDO.Message")
With $h
.Subject = $f
.Sender = $d
.From = $d
.To = $e
.TextBody = $g
;.AddAttachment ("");req full dictonairy
EndWith
With $h.Configuration.Fields
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $a
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $b
.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $c
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
EndWith
$h.Send
Return
EndFunc;==>Emailx

If i try and run I get 'error line 39', the send line...

Thanks

Share this post


Link to post
Share on other sites

Nobody knows?

I've been fiddling around with it but to no avail.

I got an error 50 or 53 at one point.

Share this post


Link to post
Share on other sites

I've been messing with smtp mailing for a few days now to no avail. No matter what script I try, one of two things happen; it appears to work but the email is never recieved, or it gives errors similar to what you recieved. I've tried sending from my own PC, and using a localhost smtp server, and others, but nothing.


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

I've been messing with smtp mailing for a few days now to no avail. No matter what script I try, one of two things happen; it appears to work but the email is never recieved, or it gives errors similar to what you recieved. I've tried sending from my own PC, and using a localhost smtp server, and others, but nothing.

Theres lots of topics on the forum about it.

Hopefully somebody will show us an example script, maybe even sticky it so people don't have to keep asking.

Regards

rage

Share this post


Link to post
Share on other sites

I know there are many topics about this...I'v elooked at them all, and tried all the scripts. None of them have worked, as I stated.


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

I know there are many topics about this...I'v elooked at them all, and tried all the scripts. None of them have worked, as I stated.

Hmm.

The CDO object scripts found on the forum are functional; I migrated to using CDO after running into an issue that forced me to migrate from blat.

If one is having difficulty using the CDO object, install your own mailserver for testing. This enables you to see the SMTP Server logs and might point you in a better direction.

WRT gmail.... if you have a problem it is likely w/ your gmail account settings not being what you think they might be. First, POP access must be turned on, and then the client configuration must be correct. Use a different email client to ensure that you can get ANY mail client to work.

Thirdly, remember that all internet traffic is subject to the whims / policies / reliability of the ISP. Proxies, routers, firewalls, bandwidth limiters, usage quotas, and failed / misconfigured hardware, along with other members of the fairy folk can and do affect what actually gets sent and received.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Hi rage,

I use also the _INetSmtpMailCom() ; created by Jos. And it works fine. I've no trouble with this.

What error-message get you?


Best Regards BugFix  

Share this post


Link to post
Share on other sites

The error messages are saying obj send won't work...

Can you guys show me your working scripts?

Thanks

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I fixed it!!!

The reason it wasn't working is due to the authentication, below is a WORKING script that works with GMAIL.

Hopefully this will help everyone.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.1.1.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
$a = "smtp.gmail.com"
$b = "myemail@gmail.com"
$c = "password"

Emailx("whoitisfrom@gmail.com", "whoitisgoingto@hotmail.com", "Subject", "Text Body")

Func Emailx($d, $e, $f, $g)
$h = ObjCreate ("CDO.Message")
With $h
.Subject = $f
.Sender = $d
.From = $d
.To = $e
.TextBody = $g
;.AddAttachment ("C:\Documents and Settings\myname\Desktop\files\file.txt");needs full path- optional
EndWith
With $h.Configuration.Fields
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $a
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $b
.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $c
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 90
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
EndWith
$h.Send
Return
EndFunc;==>Emailx

I hope this helps.

Edited by rage

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

The error messages are saying obj send won't work...

I doubt seriously that you have provided the exact text of the error message. You have multiple statements attesting that we have experienced success w/ jdeb's implementation of the CDO object, so we KNOW that it works --

Question: What is yet another (presumably customized) implementation going to do for you?

Answer: Fail due to the underlying issue you have not yet identified / addressed.

Have you taken any of the steps I outlined to ensure that you can do what you want with another tool?

To reiterate:

While Not $HaveWorkingEmailClient
    $WorkingEmailSettings = ProperlyConfigureEmailClient()
Wend

ForEach $Setting in $WorkingEmailSettings
   If $Setting.Value <> $Autoit($Setting).Value Then AlterAutoitSetting($Setting,$Setting.Value)
Next

edit: clarity

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

I have fixed it now, depending on scripts the error messages would vary. I tested my SMTP server using a different program to check that it works and it does, so then i knew the problem was with the code.

In my original posts I stated the EXACT error messages. Because of your statements of success with the other scripts I knew it was a problem with the way I was using it and realised,

The SMTP server works with other programs

The script works for other people

It must be how the script interacts with the SMTP server, and I fixed it, it requires authorisation checks.

Thanks for all input, I think you may have misinterpreted my posts 'flyingboz'. Trouble with forums, no tone of voice, expression etc.

Many Thanks

Rage

Share this post


Link to post
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
Sign in to follow this  
Followers 0