1 (edited by kalyan 2016-11-11 16:30:05)

Topic: Sending mails by VBS-scripts (Windows)

======== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.5-1
- Linux/BSD distribution name and version: CentOS 7
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): mysql
- Web server (Apache or Nginx):nginx
- Manage mail accounts with iRedAdmin-Pro? no
- Related log if you're reporting an issue:
====

Hi, friends
I'm trying to use my mail server to send messages by VBS-scripts (CDO)
I use this construction to send messages through yandex:

Dim o_Mess, v_Conf
v_Conf = "[url]http://schemas.microsoft.com/cdo/configuration/[/url]"
Set o_Mess = CreateObject("CDO.Message")
With o_Mess
    .To = "admin@mydomain.com" 'receiver
    .From = "kalyan <myyamail@ya.ru>" 'sender name and e-mail
    .Subject = "Test CDO_msg s" 'mail subject
    .TextBody = msg 'message body

With .Configuration.Fields
    .Item(v_Conf & "sendusing") = 2 
    .Item(v_Conf & "smtpserver") = "smtp.yandex.ru" 
    .Item(v_Conf & "smtpauthenticate") = 1
    .Item(v_Conf & "sendusername") = "myyamail@ya.ru" 
    .Item(v_Conf & "sendpassword") = "password" 
    .Item(v_Conf & "smtpserverport") = 465
    .Item(v_Conf & "smtpusessl") = true 
    .Item(v_Conf & "smtpconnectiontimeout") = 30 
    .Update
End With
    .send
End With
Set o_Mess = Nothing

It works, messages are well sent and received either. VBS-construction is checked and working

When I try to use the same code to send messages through my own server (I properly change server address, sender_e-mail and user credentials and can post here my changed file, though I don't see any avail of it) I get this error: something like "The transport failed to connect to the server" (error is in Russian)

this moment on my server pretty much information is captured in log (I enclosed file with it to avoid posting about 250 lines right here)
Could you help me to figure out the reason of "lost connection after CONNECT from unknown (my IP here as unknown)"?

STARTTLS
I tried also to use "sendtls" instead of "smtpusessl" :
Configuration.Fields.Item(v_Conf & "sendtls") = true
instead of
Configuration.Fields.Item(v_Conf & "smtpusessl")
and 587 tcp_port respectively and I've got error: "server response: 530 5.7.0 Must issue a STARTTLS command first"
with following information in log:

Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 220 mailsrv.MYDOMAIN.com ESMTP Postfix
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: < unknown[192.168.1.122]: EHLO ntbor02
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: match_list_match: unknown: no match
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: match_list_match: 192.168.1.122: no match
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-mailsrv.MYDOMAIN.com
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-PIPELINING
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-SIZE 15728640
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-ETRN
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-STARTTLS
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-ENHANCEDSTATUSCODES
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250-8BITMIME
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 250 DSN
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: < unknown[192.168.1.122]: MAIL FROM: <admin@orelcom.com>
Nov 11 09:03:59 mailsrv postfix/submission/smtpd[7234]: > unknown[192.168.1.122]: 530 5.7.0 Must issue a STARTTLS command first
Nov 11 09:05:11 mailsrv postfix/smtps/smtpd[7231]: idle timeout -- exiting
Nov 11 09:07:22 mailsrv postfix/submission/smtpd[7234]: < unknown[192.168.1.122]: QUIT

Later I've seen CDO doesn't support connection through STARTTLS, it is stated on microsoft site

So could you help me to make my VBS-scripts send messages through tcp_465_ssl\tls (with plain authentication or otherwise)

P.S.: I've enabled SMTPS previously, of course. It's accessible by telnet on 465 port and by MS_Outlook_mail_client either. So I can send mails using Outlook and SMTPS but I'm not able to use it right out of VBS-scripts

PPS.: I forgot to mention that line "smtpd_tls_auth_only = yes" is uncommented in main.cf postfix conf file

Appreciate any kind of your help here

Post's attachments

maillog.txt 22.12 kb, 3 downloads since 2016-11-11 

You don't have the permssions to download the attachments of this post.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Sending mails by VBS-scripts (Windows)

Please follow Enable SMTPS service (SMTP over SSL, port 465) tutorial if you want to achieve SSL over 465.

3

Re: Sending mails by VBS-scripts (Windows)

ketan.aagja wrote:

Please follow Enable SMTPS service (SMTP over SSL, port 465) tutorial if you want to achieve SSL over 465.

I mentioned that SMTPS is enabled already. I use it from my MS Outlook mail-client. checked more then twice

4

Re: Sending mails by VBS-scripts (Windows)

following works for me on my testing server:

'Usage:        cscript sendemail.vbs <email_recipient@example.com> "<subject_line>" "<email_body>" "<optional:email_attachment_path>"
'Ex. No attach:    cscript sendemail.vbs example@gmail.com "test subject line" "test email body"
'Ex. W/ attach:    cscript sendemail.vbs example@gmail.com "test subject line" "test email body" "c:\scripts\log.txt"


'***********
'****CONFIGURE THE FROM EMAIL ADDRESS AND PASSWORD

Const fromEmail    = "email_sender@gmail.com"
Const password    = "password"

'****END OF CONFIGURATION
'***********

Dim emailObj, emailConfig
Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = fromEmail
emailObj.To       = WScript.Arguments.Item(0)
emailObj.Subject  = WScript.Arguments.Item(1)
emailObj.TextBody = WScript.Arguments.Item(2)

If WScript.Arguments.Count > 3 Then
    emailObj.AddAttachment WScript.Arguments.Item(3)
End If

Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")       = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")   = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")        = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")       = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")     = fromEmail
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")     = password
emailConfig.Fields.Update

emailObj.Send

Set emailobj    = nothing
Set emailConfig    = nothing

5

Re: Sending mails by VBS-scripts (Windows)

If port 465 (SMTP over SSL) works in Outlook, server-side settings should be fine. i have no idea why your VBS script doesn't work (and i'm not a VBS guy, cannot help at code level, sorry) sad

6 (edited by kalyan 2016-11-11 18:55:33)

Re: Sending mails by VBS-scripts (Windows)

ketan.aagja wrote:

following works for me on my testing server:

Is your testing server gmail.com?
I tested your script and it's working properly with YANDEX and with some caveats with GMAIL (My gmail account is configured not to allow connections from insecure mail clients, but it can be changed to enable aforementioned access)

but I have the same error trying to use my iredmail server in your script

did you test it on yours?

ZhangHuangbin wrote:

If port 465 (SMTP over SSL) works in Outlook, server-side settings should be fine. i have no idea why your VBS script doesn't work (and i'm not a VBS guy, cannot help at code level, sorry) sad

Thank you, not-a-VBS-guy, for taking part wink

PS.: Ketan, the errors on my server and on gmail are different:
gmail server responce: transport error code 0x80040217: not available
my iredmail server responce: transport failed to connect to the server (not exactly so, i just translated it from my language) without any error code

7

Re: Sending mails by VBS-scripts (Windows)

Ok, it's working now
I just tried to send mails by powershell script:

 
##############################################################################
$From = "admin@MYDOMAIN.com"
$To = "testaccount@ya.ru"
$Cc = "testaccount@gmail.com"
$Attachment = "C:\temp\Some random file.txt"
$Subject = "PowerShell_Test"
$Body = "Has it been really delivered?"
$SMTPServer = "mail.MYDOMAIN.com"
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential (Get-Credential)# -Attachments $Attachment
############################################################################## 

and it gave me a hint - error of invalid ssl certificate (self-signed) so i've got a free one and installed it. After this action my powershell script sent out a mail. Then I tried to amend smtp_port and set it 465 - script ceased work! Connection shut by timeout.
Strange to say the same behavior I encountered in linux using mailx:

 "test mail from linux environment" | mailx -v -r "admin@MYDOMAIN.com" \
-s "mailx-test-msg" \
-S smtp="mail.MYDOMAIN.com:587" \
-S smtp-use-starttls \
-S nss-config-dir=/etc/pki/nssdb/ \
-S smtp-auth=login \
-S smtp-auth-user="admin@MYDOMAIN.com" \
-S smtp-auth-password="pass" \
-S ssl-verify=ignore \
recipient@test.com

It works perfectly over 587 and fails over 465 port, disconnecting by timeout
Ok, that doesn't matter. I'd like to avoid using SMTPS at all if only VBS would be able to send messages over 587&STARTTLS, but it can't

Right after getting and installing a trusted ssl certificate I endeavored to test my VBS (over 465 SMTPS) and it passed...

So now I can send mails using STARTTLS over 587 port in my PowerShell and bash scripts (and I was able to, I guess, by mailx with ssl-verify=ignore option)
And my VBS-scripts can send messages over 465 port of SMTPS.

Hope this post will save some time to anyone smile

8

Re: Sending mails by VBS-scripts (Windows)

Thanks for sharing. smile