PDA

View Full Version : Simple SMTP_SSL with console mailsend



M30_NXG
01-11-2018, 16:43
Hello,
to all.

My first posting is a short console solution, inspired from a
existing VB-script.
Realized with an minimalistic code skeleton for proofing
and demonstrating the idea.

The simple recipe: iDispatch is used. ;-)
So the VBS code needs only smooth changes to work within Thinair. ;-)

- What we do:
We send a mail message via console without using Thunderbird, Outlook,
etc. mail clients
To realize this i use mailsend, a free console textbased mail client.


Necessary steps..

1.)
look at:
https://github.com/muquit/mailsend/releases/
https://github.com/muquit/mailsend/#features

2.)
Download mailsend v1.19 - Latest stable version
mailsend1.19.exe.zip - zipped windows binary.

UNZIP it in drive:Dir\path of your choice.
If you wish, rename it to MS.EXE (no must, but it's handy)

3.)
Adjust the variables for SMTP-Mail and the above (2.))
Drive:Dir\path combination to your situation.
See the comments in the source file.

4.)
Feel free to modify and use
Thinair - hit F5 - should do the rest

Stumbeling...
In Line 83 i have a litte problem with the OS_Shell command.
The Body is cutted after about 240-250 chars length.
The "pure VBS solution" , see line 86 seems to work.
Any idea ?

Thanks

Ben



' SimpleSMTP_SSL
'-----------------------
' based on an existing VB-Script solution

'-- Prepare :
' (1.) Download mailsendxxx from :
' https://github.com/muquit/mailsend/releases/
' https://github.com/muquit/mailsend/#features

' to an Dir\Path of your choice. Manually rename it to MS.EXE
' Short name is better to handle, but no must.
'=============================================================
Uses "Console"
Uses "OS"
'-----------Change here for your suits ---------
' eventual look at your Mail- Client settings to get the right settings
' (2.) User / Provider data... / SMTP Server
'-----------------------------------------------
Dim Msender As String ="XXXXX@YZ.de" 'SenderName -- sender@xyz.de
Dim Mserver As string ="SMTPxxxx.de" 'SMTP Server -- smtpserver.it
Dim Mpass As string ="##########" 'Passwort -- your Mail PWD
Dim Mreceiver As String ="RRRRR@Mail.de" 'receiver -- to
Dim sSLLPort as string = "465" ' SSL Port.. -- SSL port
'-----------------------------------------------
'-- Change here the location of mailsend.exe ************
Dim MSendeApp As String ="c:\skripte\ms.exe" 'MS.EXE is here at home <--


String sAPP_Version = """ TB Simple SMTP SSL Tester - send by PC : """
'--------- MAIN ---------------
Function TBMain() As Long
Call Mail_send
PrintL "**__END__ " & crLF & "( Hit Key to Exit )**"
WaitKey
End Function
' ----- END MAIN ---------------

'------------------------------------------
Sub Mail_send() 'poor man solution ;-)
'------------------------------------------
''** WARNIG. MS.EXE is sensible on missing or wrong double quotes or spaces
''** between the parameters. Symptom : No mail is sended
Dim oMsg as idispatch
Dim SendMail_Wrapper as String
Dim TestBody as String
'-- here you can chain your Body text
TestBody ="1111111110" & $LF & _
"2222222220" & $LF & _
"3333333330" & $LF & _
"4444444440" & $LF & _
"5555555550" & $LF & _
"6666666660" & $LF & _
"7777777770" & $LF & _
"9999999990" & $LF & _
"AAAAAAAAA0" & $LF & _
"BBBBBBBBB0" & $LF & _
"CCCCCCCCC0" & $LF & _
"DDDDDDDDD0"
'--magic ---IdisPatch--sorry no CHK -> on if IsComObject <-in this sample-
oMsg = Newcom("WScript.Shell")

'-- simple wrapper for MS.EXE arguments
' (- v Option) ist active for dbg ;-)
'------------------------------------------------
SendMail_Wrapper = " -f " & Mreceiver & _
" -t " & Mreceiver & _
" -ssl -port " & sSLLPort & " -auth -smtp " & Mserver & _
" -user " & Msender & _
" -pass " & Mpass & _
" -sub " & sAPP_Version & OS_GetComputerName & _
" -v " & " -M " & " " & _
TestBody
'-- feel free to add more Body- text
'--------------------------------------------------------

'litte dbg, because of problem with OS_Shell '
PrintL "**dbg_Info Send-Packet **:" , SendMail_Wrapper
PrintL "**dbg_Info Length :" , Len(SendMail_Wrapper) & crLf

'?? Here i am struggeling with the native OS_Shell command
' --- only ca. 240 - 250 Chars are transported , then cut ? why ? mh, mh?
' Perhaps MS.EXE ?
'OS_Shell(MSendeApp & " " & SendMail_Wrapper , %OS_WNDSTYLE_MAXIMIZED, %OS_SHELL_SYNC)

'--- no problem with Len in this solution (SendMail_Wrapper)
oMsg.run (MSendeApp & " " & SendMail_Wrapper, 0, True)

oMsg = Nothing

End Sub
''//EOF

DirectuX
01-11-2018, 19:59
Hi, M30_NXG




'?? Here i am struggeling with the native OS_Shell command
' --- only ca. 240 - 250 Chars are transported , then cut ? why ? mh, mh?
' Perhaps MS.EXE ?
'OS_Shell(MSendeApp & " " & SendMail_Wrapper , %OS_WNDSTYLE_MAXIMIZED, %OS_SHELL_SYNC)


just an idea (I'm a newcomer at ThinBasic) : have you try with OS_ShellExecute ?


hInstance = OS_ShellExecute(Open, MSendeApp , SendMail_Wrapper, "c:\skripte\",%SW_SHOWMAXIMIZED)

ErosOlmi
01-11-2018, 20:18
Hi Ben,

thanks a lot for this great entrance in thinBasic.

I didn't know about MailSend, it can be very useful.
thinBasic has a SMTP module but MailSend support ESMPT and IPV6
Very compact, I will study it.

And yes, thinBasic has OS_Shell functions but the use of iDispatch is great.
I like the idea to use all the tools that are available and find different ways to do the same things.

I will check OS_Shell limitations, maybe I can improve command line max number of chars

Ciao
Eros

ErosOlmi
01-11-2018, 21:45
I've developed a new Shell function without command line limitations.
It will be a new keyword directly in Core engine of thinBasic so no need to load OS module to use it.
Will be present in next release.

Ben, thanks for spotting it