Sign in to follow this  
Followers 0
tinygreypixel

Sending mail from script

16 posts in this topic

Hi,

I tried to make a script that sends email using INetSmtpMail, but as I see, this function doesn't support smtp authentication (username/password). Is there a solution?

Share this post


Link to post
Share on other sites



If you know the protocol, you could modify the UDF slightly to send any authentication information. If it works, you may as well suggest it to be applied to the distributed UDF.

Share this post


Link to post
Share on other sites

If you know the protocol, you could modify the UDF slightly to send any authentication information. If it works, you may as well suggest it to be applied to the distributed UDF.

That's the problem, I don't know the protocol. I was hoping that someone got a working email sending function that supports smtp authentication. :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This might work [edit] I added authentication but have not tested it. [/edit]

Func Email()
$objMessage = ObjCreate("CDO.Message")
$objMessage.Subject = "Your Subject"
$objMessage.From = "Email From field"
$objMessage.To = "Mail To"
$objMessage.CC = "CC recipient"
$objMessage.BCC= "BCC recipient"
$objMessage.TextBody = "Email Body "

;==This section provides the configuration information for the remote SMTP server.
;==Normally you will only change the server name or IP.
$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

;Name or IP of Remote SMTP Server
$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP Server"

;Server port (typically 25)
$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

;Not Tested
 $objMessage.Configuration.Fields.Item _ 
("http://schemas.microsoft.com/cdo/configuration/sendusername") = $smtpuser
;Not Tested
 $objMessage.Configuration.Fields.Item _ 
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $smtppass

$objMessage.Configuration.Fields.Update

;==End remote SMTP server configuration section==

$objMessage.Send
EndFunc
Edited by Legacy99

Share this post


Link to post
Share on other sites

This might work [edit] I added authentication but have not tested it. [/edit]

...

Thanks, I'll try it later and will be back with the result. :)

Share this post


Link to post
Share on other sites

Doesn't work. :) It says:

$objMessage.Send

$objMessage.Send^ERROR

Error: The requested action with this object has failed.

Share this post


Link to post
Share on other sites

I don't have the script here to test it but did you include?

#include <IE.au3>

#include <INet.au3>

Not sure if that makes a difference

And check the username and password lines I added, I noticed the underscore in "$objMessage.Configuration.Fields.Item _ " is missing a space, I will edit it

Share this post


Link to post
Share on other sites

I don't have the script here to test it but did you include?

#include <IE.au3>

#include <INet.au3>

Not sure if that makes a difference

And check the username and password lines I added, I noticed the underscore in "$objMessage.Configuration.Fields.Item _ " is missing a space, I will edit it

No, it doesn't make any difference if I include those files. :) I've corrected the underscores, that was not a problem, it seems we have to use another object type, or dunno. The _INetSmtpMail function looks a little complicated, but maybe it could be modified to have smtp authentication.

Share this post


Link to post
Share on other sites

I have not tested it but I think you want this modified version of _INetSmptMail. The files are in the second post.

Share this post


Link to post
Share on other sites

I got it working with Gmail, I assume other ISP's that use a different port from 25 and require authentication will be similar

you need to add:

$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true

$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Username@gmail.com"

$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"

$objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465oÝ÷ Ù*"¶ÈhºWe¢%G­+ ¢eyªçx&j׫©Hz0jZ-Þiº.´ β·&®¶­sdgVæ2VÖ¢b33c¶ö&¤ÖW76vRÒö&¤7&VFRgV÷C´4DòäÖW76vRgV÷C²¢b33c¶ö&¤ÖW76vRå7V&¦V7BÒgV÷Cµ÷W"7V&¦V7BgV÷C°¢b33c¶ö&¤ÖW76vRäg&öÒÒgV÷C´VÖÂg&öÒfVÆBgV÷C°¢b33c¶ö&¤ÖW76vRåFòÒgV÷C´ÖÂFògV÷C°¢b33c¶ö&¤ÖW76vRä42ÒgV÷C´42&V6VçBgV÷C°¢b33c¶ö&¤ÖW76vRä$43ÒgV÷C´$42&V6VçBgV÷C°¢b33c¶ö&¤ÖW76vRåFWD&öGÒgV÷C´VÖÂ&öGgV÷C° £³ÓÕF26V7Föâ&÷fFW2FR6öæfwW&Föâæf÷&ÖFöâf÷"FR&VÖ÷FR4ÕE6W'fW"ࣳÓÔæ÷&ÖÆÇ÷RvÆÂöæÇ6ævRFR6W'fW"æÖR÷"à¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6VæGW6ærgV÷C²Ò" £´æÖR÷"öb&VÖ÷FR4ÕE6W'fW ¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6×G6W'fW"gV÷C²ÒgV÷C¶vÖÂç6×Gæ6öÒgV÷C° ¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6×GWFVçF6FRgV÷C²Ò ¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6×GW6W76ÂgV÷C²ÒG'VP ¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6VæGW6W&æÖRgV÷C²ÒgV÷CµW6W&æÖTvÖÂæ6öÒgV÷C° ¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6VæG77v÷&BgV÷C²ÒgV÷Cµ77v÷&BgV÷C° £µ6W'fW"÷'BG6ÆÇ#R¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2äFVÒð¢gV÷C¶GG¢ò÷66VÖ2æÖ7&÷6ögBæ6öÒö6Fòö6öæfwW&Föâ÷6×G6W'fW'÷'BgV÷C²ÒCcP¢¢b33c¶ö&¤ÖW76vRä6öæfwW&FöâäfVÆG2åWFFP £³ÓÔVæB&VÖ÷FR4ÕE6W'fW"6öæfwW&Föâ6V7FöãÓÐ ¢b33c¶ö&¤ÖW76vRå6Væ@¤VæDgVæ0

Share this post


Link to post
Share on other sites

I think there is a bug in the file _INetSmtpMail.au3 used in the topic I linked to. Take a look at my post for changes. I also added a line:

If not IsArray($as_Body) Then $as_Body = StringSplit($as_Body, @CRLF)

at the top of the function _INetSmtpMail to make sure it did not malfunction by a misunderstanding.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

I think there is a bug in the file _INetSmtpMail.au3 used in the topic I linked to. Take a look at my post for changes. I also added a line:

If not IsArray($as_Body) Then $as_Body = StringSplit($as_Body, @CRLF)

at the top of the function _INetSmtpMail to make sure it did not malfunction by a misunderstanding.

Thanks for the correction! I think you are right. :)

By the way, adding that line you suggested, it generates extra empty lines, as stated in the autoit help of StringSplit:

"Caution if you use the macro @CRLF you are referring to a 2 character string so you will generate extra blanks lines."

Looks good too. :) But the one that Uten suggested is perfect for me. :) Thank you all for your help. :D

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