Sign in to follow this  
Followers 0
Tigerweld

Sending Email

21 posts in this topic

noob here and I have spent hours trying to figure this out. I can use the code below, but I want to be able to change the variables if conditions are met. I just need to know how. Should I place it in a seperate file and include it? If I do, how much should I place in the file? and how do I call it? Just use call _iNetSmtpCom ?

#Include<file.au3>

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

;##################################

; Include

;##################################

#Include<file.au3>

;##################################

; Variables

;##################################

$s_SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED

$s_FromName = "Name" ; name from who the email was sent

$s_FromAddress = "your@Email.Address.com" ; address from where the mail should come

$s_ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED

$s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be

$as_Body = "" ; 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 = "CCadress1@test.com" ; address for cc - leave blank if not needed

$s_BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed

$s_Username = "******" ; username for the account used from where the mail gets sent - REQUIRED

$s_Password = "********" ; password for the account used from where the mail gets sent - REQUIRED

$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 & " 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

Share this post


Link to post
Share on other sites



I want to be able to change the variables if conditions are met.

If $s_ToAddress = "johnsmith@autoitrocks.com then 
$s_CcAddress = "johnsmithsbrother@autoitrocks.com
$s_ToAddress = "i_don't_want_this_to_go_to_john_any_more@autoit.com
EndIf

That's my understanding of your problem


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

Do I place the function in an au3 file in the include folder and include it? What is the proper syntax to call it?

call func _inetsmtpmailcom() ???

Where do I place the code below?

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

;##################################

; Include

;##################################

#Include<file.au3>

;##################################

; Variables

;##################################

$s_SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED

$s_FromName = "Name" ; name from who the email was sent

$s_FromAddress = "your@Email.Address.com" ; address from where the mail should come

$s_ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED

$s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be

$as_Body = "" ; 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 = "CCadress1@test.com" ; address for cc - leave blank if not needed

$s_BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed

$s_Username = "******" ; username for the account used from where the mail gets sent - REQUIRED

$s_Password = "********" ; password for the account used from where the mail gets sent - REQUIRED

$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 & " Description:" & $rc)

EndIf

Share this post


Link to post
Share on other sites

anyone? :)

Share this post


Link to post
Share on other sites

$toAddress = InputBox("Some program", "Enter an email address...")

_INetSmtpMail($someServer, "myadress@hotmail.com", $toAdress...

I think _INetSmtpMail is now in AutoIt as a function so you don't need all that code, but rather just what I have above with correct parameters...


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

thank God! But when I try that I'm getting errors. First is my code, errors are below.

#include<file.au3>

#include<inet.au3>

If FileExists("\\main\data\mis\idt_reports\datalink\datalink_report1.dat") Then

; if old txt file on datalink exist, delete it before starting

If FileExists("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt") Then

filedelete("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

$s_SmtpServer = "smtp.gmail.com"

$s_FromName = "Datalink"

$s_FromAddress = "datalink@gmail.com"

$s_ToAddress = "mis@mycompany.com"

$s_Subject = "DATALINK DOWNLOAD HAS STARTED"

Func _INetSmtpMail( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject)

EndIf

; get modified date/time stamp of current dat file on main and copy it to the archive

; copy it to datalink server naming it to txt extension

$t = FileGetTime("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", 0 ,1)

If Not @error Then

FileCopy("\\main\data\mis\idt_reports\datalink\datalink_report1.dat" , "\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

FileMove("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", "\\main\data\mis\idt_reports\datalink\archive\" & $t & ".txt" )

EndIf

Else

EndIf

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(23,1) : ERROR: missing EndIf.

Func

^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(14,88) : REF: missing EndIf.

If FileExists("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt") Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(23,1) : ERROR: missing EndIf.

Func

^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(12,80) : REF: missing EndIf.

If FileExists("\\main\data\mis\idt_reports\datalink\datalink_report1.dat") Then

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(23,90) : ERROR: _INetSmtpMail() already defined.

Func _INetSmtpMail( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(25,2) : ERROR: syntax error

EndIf

^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3 - 4 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites

I'm getting an error about my function. What am I doing wrong?

CODE

#include<file.au3>

#include<inet.au3>

If FileExists("\\main\data\mis\idt_reports\datalink\datalink_report1.dat") Then

; if old txt file on datalink exist, delete it before starting

If FileExists("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt") Then

filedelete("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

$s_SmtpServer = "smtp.gmail.com"

$s_FromName = "Datalink"

$s_FromAddress = "datalink@gmail.com"

$s_ToAddress = "mis@mycompany.com"

$s_Subject = "DATALINK DOWNLOAD HAS STARTED"

call Func _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject)

EndIf

; get modified date/time stamp of current dat file on main and copy it to the archive

; copy it to datalink server naming it to txt extension

$t = FileGetTime("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", 0 ,1)

If Not @error Then

FileCopy("\\main\data\mis\idt_reports\datalink\datalink_report1.dat" , "\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

FileMove("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", "\\main\data\mis\idt_reports\datalink\archive\" & $t & ".txt" )

EndIf

Else

EndIf

CODE

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /in "C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3" /autoit3dir "C:\Program Files\AutoIt3"

+>19:27:07 Starting AutoIt3Wrapper v.1.9.4

>Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(23,6) : ERROR: syntax error

call Func

~~~~~^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3 - 1 error(s), 0 warning(s)

!>19:27:08 AU3Check ended.rc:2

+>19:27:13 AutoIt3Wrapper Finished

>Exit code: 0 Time: 6.078

Share this post


Link to post
Share on other sites

I'm getting an error about my function. What am I doing wrong?

CODE

#include<file.au3>

#include<inet.au3>

If FileExists("\\main\data\mis\idt_reports\datalink\datalink_report1.dat") Then

; if old txt file on datalink exist, delete it before starting

If FileExists("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt") Then

filedelete("\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

$s_SmtpServer = "smtp.gmail.com"

$s_FromName = "Datalink"

$s_FromAddress = "datalink@gmail.com"

$s_ToAddress = "mis@mycompany.com"

$s_Subject = "DATALINK DOWNLOAD HAS STARTED"

call Func _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject)

EndIf

; get modified date/time stamp of current dat file on main and copy it to the archive

; copy it to datalink server naming it to txt extension

$t = FileGetTime("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", 0 ,1)

If Not @error Then

FileCopy("\\main\data\mis\idt_reports\datalink\datalink_report1.dat" , "\\datalink\datalink\banktrack\datadownload\datalink_report1.txt")

FileMove("\\main\data\mis\idt_reports\datalink\datalink_report1.dat", "\\main\data\mis\idt_reports\datalink\archive\" & $t & ".txt" )

EndIf

Else

EndIf

CODE

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /in "C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3" /autoit3dir "C:\Program Files\AutoIt3"

+>19:27:07 Starting AutoIt3Wrapper v.1.9.4

>Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3(23,6) : ERROR: syntax error

call Func

~~~~~^

C:\Documents and Settings\tscott\My Documents\auto it scripts\datalinkDownload.au3 - 1 error(s), 0 warning(s)

!>19:27:08 AU3Check ended.rc:2

+>19:27:13 AutoIt3Wrapper Finished

>Exit code: 0 Time: 6.078

Question... do you know how to actually call a function? (Not being mean here, seriously asking).

You don't:

call Func _INetSmtpMail(oÝ÷ Ûú®¢×¡Æ¥ØZµû§rب*.²)©&®¶­seôæWE6×GÖÂb33c·5õ6×G6W'fW"Âb33c·5ôg&öÔæÖRÂb33c·5ôg&öÔFG&W72Âb33c·5õFôFG&W72Âb33c·5õ7V&¦V7B
without the "call Func "

I didn't even look past that point to be honest.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

SWEET JESUS! No, I didn't. I tried every combination I could think of! lol

question (if you have ever used smtp before), will I need an actual smtp account somewhere to make this work? I'm at home or else I would try it. I just want to know if I need to configure the email client on the server this will be running on. I saw on the other inetsmtpmailcom function it required a login to an smtp server such as gmail.

oh, and thank you so much!!!

Share this post


Link to post
Share on other sites

SWEET JESUS! No, I didn't. I tried every combination I could think of! lol

question (if you have ever used smtp before), will I need an actual smtp account somewhere to make this work? I'm at home or else I would try it. I just want to know if I need to configure the email client on the server this will be running on. I saw on the other inetsmtpmailcom function it required a login to an smtp server such as gmail.

oh, and thank you so much!!!

Nuther question. Do you know what SMTP is?

:)

Share this post


Link to post
Share on other sites

Simple Mail Transfer Protocol, yes, but some apps require that the actual workstation/server have a mail client configured. Take for example, sql server 2005. If you want to configure the notification feature you must install a mail client.

Share this post


Link to post
Share on other sites

I don't see mentioning of ports in this function. Got any idea?

btw, tell my sister I said hello! :)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

You obviously haven't read the damn script that you posted well enough to recognise the fact that it is there. $IPPort = 25 or $IPPort = 465 for Gmail...

That is in the inetsmtpmailcom event. Achilles said to use inetsmtp instead so I started looking into that function and noticed it doesn't have the $IPPort varible. If I knew how to use the com event that Jos wrote I would use it. We don't use smtp for email, instead we use imap.

I'm not asking for a cure for cancer, just a little help.

Share this post


Link to post
Share on other sites

ok, I think I'm closer to understanding it, however, I don't know how to change the subject varible. Please take a look and let me know what I'm missing here. I get the email, but there isn't a subject. It's just blank.

#include <inetsmtpmailcom.au3>

If FileExists("c:\test1.txt") Then
$s_Subject = "FILE EXIST!"

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

Else
    $s_Subject = "FILE DOES NOT EXIST!"

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

Share this post


Link to post
Share on other sites

This line:

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

Should look like this assuming you have set the variables correctly:

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

There is a nice example in the Examples forum that shows how to do it. :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This line:

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

Should look like this assuming you have set the variables correctly:

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

There is a nice example in the Examples forum that shows how to do it. :)

Doing that alone didn't fix it. Just for giggles I commented out the following in your UDF and it worked. Is that right? btw, I did not see an example like mine where they were trying to change variables in an 'IF' statement.

$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

Share this post


Link to post
Share on other sites

Doing that alone didn't fix it. Just for giggles I commented out the following in your UDF and it worked. Is that right? btw, I did not see an example like mine where they were trying to change variables in an 'IF' statement.

$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
:) This part in not in the UDF but calls the UDF.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

:) This part in not in the UDF but calls the UDF.

Jos

Now you tell me! ;) How much of your code should be in the UDF and what should be in main? (for lack of better word)

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