Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Help with SMTP mail

$
0
0
Let me start by saying this was working. We just migrated from Novel Groupwise to Exchange.

On Groupwise the following worked to send mail...

#include <_INetSmtpMailCom.au3>
Global $SmtpServer = "111.22.33.44" ; address for the smtp-server to use - REQUIRED
Global $FromName = "Test Server" ; name from who the email was sent
Global $FromAddress = "Help-Desk@nomail.com" ; address from where the mail should come
Global $ToAddress = "recipient@nomail.com" ; destination address of the email - REQUIRED
Global $Subject = "TESTING" ; subject from the email - can be anything you want it to be
Global $Body = "This is a test of the emergency broadcast system." ; the messagebody from the mail - can be left blank but then you get a blank mail
Global $AttachFiles = "" ; the file you want to attach- leave blank if not needed
Global $CcAddress = "" ; address for cc - leave blank if not needed
Global $BccAddress = "" ; address for bcc - leave blank if not needed
Global $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
Global $Username = "user" ; username for the account used from where the mail gets sent - REQUIRED
Global $Password = "pass" ; password for the account used from where the mail gets sent - REQUIRED
Global $IPPort = 25 ; port used for sending the mail
Global $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($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)


Since the switch to exchange the above code yields the attached error.smtp error.jpg

I don't know if it is relevant or not, but previously SMTP traffic was sent to the "gwia" server. Since the switch to Exchange I was instructed to send SMTP traffic to the iis server.

Before anyone jumps on the 'Exchange/iis isn't configured properly bandwagon' I would like to point out that the following code DOES work with Exchange...

$sUser = "";YourEmail
$sPass = "" ;YourPassword
$sServer = "smtp.live.com"
$sFrom = "";YourEmail
$sTo = "" ;ToEmail
$sPort = 25
$sObject = "Test"
$sMessage = "MyMessage"
_SendMail(_Base64Encode($sUser), _Base64Encode($sPass), $sServer, $sFrom, $sTo, $sPort, $sObject, $sMessage)
Func _SendMail($user, $pass, $server, $from, $to, $port = 25, $obj = "object", $msg = "message", $visibile = False)
$msg = StringReplace($msg, @CRLF & "." & @CRLF, @CRLF & "," & @CRLF)
$limit_time = 15000
If $visibile = True Then SplashTextOn("Send Email", "Starting Connection...", 200, 100)
TCPStartup()
$main_sock = TCPConnect(TCPNameToIP($server), $port)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
If $visibile = True Then SplashTextOn("Send Email", "Connection OK!" & @CRLF & "Dialog with server...", 200, 100)
TCPSend($main_sock, "HELO Email" & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
If $visibile = True Then SplashTextOn("Send Email", "Connection OK!" & @CRLF & "Login...", 200, 100)
TCPSend($main_sock, "AUTH LOGIN" & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
TCPSend($main_sock, $user & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
TCPSend($main_sock, $pass & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
If $visibile = True Then SplashTextOn("Send Email", "Connection OK!" & @CRLF & "Sending email...", 200, 100)
TCPSend($main_sock, "MAIL FROM:<" & $from & ">" & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
TCPSend($main_sock, "RCPT TO:<" & $to & ">" & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
TCPSend($main_sock, "DATA" & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
TCPSend($main_sock, "SUBJECT:" & $obj & @CRLF)
TCPSend($main_sock, "" & @CRLF)
TCPSend($main_sock, $msg & @CRLF & "." & @CRLF)
$timer = TimerInit()
While TimerDiff($timer) < $limit_time
	 $rec = TCPRecv($main_sock, 1000)
	 If $rec <> "" Then ExitLoop
WEnd
$timer = 0
If $rec = "" Then Return SetError(1, 0, 0)
If $visibile = True Then SplashOff()
TCPCloseSocket($main_sock)
TCPShutdown()
Return $rec
EndFunc ;==>_SendMail
Func _Base64Encode($Data, $LineBreak = 76)
Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
$Data = Binary($Data)
Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
DllStructSetData($Input, 1, $Data)
$LineBreak = Floor($LineBreak / 4) * 4
Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3)
$OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4
Local $Ouput = DllStructCreate("char[" & $OputputSize & "]")
DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
		 "ptr", DllStructGetPtr($Input), _
		 "int", BinaryLen($Data), _
		 "ptr", DllStructGetPtr($Ouput), _
		 "uint", $LineBreak)
Return DllStructGetData($Ouput, 1)
EndFunc ;==>_Base64Encode


The problem I have with the above code is that it does NOT allow me to attach files.

As a side note, I have tried the OutlookEx UDF which does work. However, it sends the mail from my account and I need to be able to send the mail from specific email address.

Any help would be greatly appreciated. I would prefer to continue using _INetSmtpMailCom.au3 if possible.

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>