четверг, 5 декабря 2013 г.

Ошибка (error) при работа с электронной почтой smtp.yandex.ru из скрипта по средствам CDO (Collaboration Data Objects)

Вот такую ошибку выдает скрипт:

---------------------------
Windows Script Host
---------------------------
Сценарий: C:\12345\Work\Scripting\eMail\send_eMail.vbs
Строка: 42
Символ: 2
Ошибка: Сервер отклонил адрес отправителя. Отклик сервера: 503 5.5.4 Error: send AUTH command first.

Код: 8004020E
Источник: (null)

---------------------------
ОК
---------------------------

Собственно сам скрипт который выдает ошибку:

Message = "Test message" Set myMail=CreateObject("CDO.Message") myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yandex.ru" myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'Your UserID on the SMTP server myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Login" 'Your password on the SMTP server myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" myMail.Subject="Sending email with CDO" myMail.From="logi@yandex.ru" myMail.To="poluchatel@gmail.com" myMail.TextBody = Message myMail.BodyPart.CharSet = "utf-8" 'myMail.AddAttachment "Login Data" myMail.Configuration.Fields.Update myMail.Send set myMail=nothing MsgBox "eMail is send!"

Долго искал причину, нашел один форум с подобной проблемой но решения там небыло, пришлось читать мануал и нашел smtpauthenticate Field тут сказано что оно(fild) имеет три параметра 1. cdoAnonymous 2. cdoBasic и третий нам не нужен ) по умолчанию без аутентификации(анонимно), в нашем случае присутствует аутентификация, нам нужно указать второй параметр "базовая аутентификация" smtpauthenticate = 1 :

Message = "Test message" Set myMail=CreateObject("CDO.Message") myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yandex.ru" myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'Your UserID on the SMTP server myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Login" 'Your password on the SMTP server myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" myMail.Subject="Sending email with CDO" myMail.From="login@yandex.ru" myMail.To="poluchatel@gmail.com" myMail.TextBody = Message myMail.BodyPart.CharSet = "utf-8" 'myMail.AddAttachment "Login Data" myMail.Configuration.Fields.Update myMail.Send set myMail=nothing MsgBox "eMail is send!"