Modify

Opened 14 years ago

Closed 12 years ago

#1818 closed Feature Request (Rejected)

(UDF) _INetSmtpMail Importance parameter

Reported by: JamesBrooks Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Inet, udf, importance, parameter, smtp, mail Cc:

Description

Since the importance of an email can be critical, I added a parameter for importance; $s_Importance which can be; "low", "normal", "high".

Personally I think an important feature to have, that or a way to allow extra headers to be added.

; #FUNCTION# ====================================================================================================================
; Name...........: _INetSmtpMail
; Description ...: Sends an email using SMTP over TCP IP.
; Parameters ....: $s_SmtpServer	- SMTP server to be used for sending email
;                  $s_FromName		- Name of sender
;                  $s_FromAddress	- eMail address of sender
;                  $s_ToAddress	- Address that email is to be sent to
;                  $s_Subject		- Subject of eMail
;				   $as_Body		- Single dimension array containing the body of eMail as strings
;				   $s_helo			- Helo identifier (default @COMPUTERNAME) sometime needed by smtp server
;				   $s_first		- send before Helo identifier (default @CRLF) sometime needed by smtp server
;				   $s_Importance	- low, normal high
;				   $b_trace		- trace on a splash window (default 0 = no trace)
; Return values .: On Success - Returns 1
;                  On Failure - 0  and sets
;											@ERROR = 1		-	Invalid Parameters
;											@ERROR = 2		-	Unable to start TCP
;											@ERROR = 3		-	Unable to resolve IP
;											@ERROR = 4		-	Unable to create socket
;											@ERROR = 5x		-	Cannot open SMTP session
;											@ERROR = 50x	-	Cannot send body
;											@ERROR = 5000	-	Cannot close SMTP session
; Author ........: Asimzameer, Walkabout
; Modified.......: Jpm, JamesBrooks
; ===============================================================================================================================
Func _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first=" ", $s_Importance = "normal", $b_trace = 0)
	If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then Return SetError(1, 0 ,0)
	If $s_helo = "" Then $s_helo = @ComputerName

	If TCPStartup() = 0 Then Return SetError(2, 0 ,0)

	Local $s_IPAddress, $i_Count
	StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")
	If @extended Then
		$s_IPAddress = $s_SmtpServer
	Else
		$s_IPAddress = TCPNameToIP($s_SmtpServer)
	EndIf
	If $s_IPAddress = "" Then
		TCPShutdown()
		Return SetError(3, 0 ,0)
	EndIf
	Local $v_Socket = TCPConnect($s_IPAddress, 25)
	If $v_Socket = -1 Then
		TCPShutdown()
		Return SetError(4, 0 ,0)
	EndIf

	Local $s_Send[6], $s_ReplyCode[6]	; Return code from SMTP server indicating success
	$s_Send[0] = "HELO " & $s_helo & @CRLF
	If StringLeft($s_helo,5) = "EHLO " Then $s_Send[0] = $s_helo & @CRLF
	$s_ReplyCode[0] = "250"

	$s_Send[1] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF
	$s_ReplyCode[1] = "250"
	$s_Send[2] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF
	$s_ReplyCode[2] = "250"
	$s_Send[3] = "DATA" & @CRLF
	$s_ReplyCode[3] = "354"

	Local $aResult = _Date_Time_GetTimeZoneInformation()
	Local $bias = -$aResult[1]/60
	Local $biasH = Int($bias)
	Local $biasM = 0
	If $biasH <> $bias Then $biasM =  Abs($bias - $biasH) * 60
	$bias =  StringFormat(" (%+.2d%.2d)", $biasH, $biasM)

	$s_Send[4] = 	"From:" & $s_FromName & "<" & $s_FromAddress & ">" & @CRLF & _
			"To:" & "<" & $s_ToAddress & ">" & @CRLF & _
			"Subject:" & $s_Subject & @CRLF & _
			"Mime-Version: 1.0" & @CRLF & _
			"Date: " & _DateDayOfWeek(@WDAY, 1) & ", " & @MDAY & " " & _DateToMonth(@MON, 1) & " " & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & $bias & @CRLF & _
			"Content-Type: text/plain; charset=US-ASCII" & @CRLF & _
			"Importance: " & $s_Importance & @CRLF & _
			@CRLF
	$s_ReplyCode[4] = ""

	$s_Send[5] = @CRLF & "." & @CRLF
	$s_ReplyCode[5] = "250"

	; open stmp session
	If __SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then Return SetError(50, 0, 0)

	; send header
	For $i_Count = 1 To UBound($s_Send) - 2
		If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then Return SetError(50 + $i_Count, 0 ,0)
	Next

	; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..)
	For $i_Count = 0 To UBound($as_Body) - 1
		; correct line beginning with a dot
		If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count]

		If __SmtpSend($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then Return SetError(500 + $i_Count, 0, 0)
	Next

	; close the smtp session
	$i_Count = UBound($s_Send) - 1
	If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then Return SetError(5000, 0, 0)

	TCPCloseSocket($v_Socket)
	TCPShutdown()
	Return 1
EndFunc   ;==>_INetSmtpMail

Attachments (0)

Change History (4)

comment:1 Changed 14 years ago by TicketCleanup

  • Version 3.3.6.1 deleted

Automatic ticket cleanup.

comment:2 follow-up: Changed 14 years ago by Zedna

There is hardcoded "charset=US-ASCII"
Maybe there could be added also new parameter "charset" ...

comment:3 in reply to: ↑ 2 Changed 14 years ago by anonymous

Replying to Zedna:

There is hardcoded "charset=US-ASCII"
Maybe there could be added also new parameter "charset" ...

It's not a charset, it's just a header.

"Importance: " & $s_Importance & @CRLF & _

This line is what I added.

comment:4 Changed 12 years ago by trancexx

  • Resolution set to Rejected
  • Status changed from new to closed

There are much more important features that function misses.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.