Jump to content

Sending mail from script


Recommended Posts

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. :)

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...