Liberty BASIC Community Forum
Special Topics and Projects >> Internet and network programming >> Send email, with optional attachments.
http://libertybasic.conforums.com/index.cgi?board=internet&action=display&num=1241531984

Send email, with optional attachments.
Post by Alyce Watson on May 5th, 2009, 08:59am

Members of the Run BASIC forum shared information about a free command line executable that allows one to send email with optional attachment. To use this, you'll need to know the specifics of your email account. The example uses gmail, but if you use a different email provider, be sure to find out the correct server and port information.

http://alycesrestaurant.com/sendemailexe.htm

Run BASIC Forum:
http://runbasic.proboards.com/
Re: Send email, with optional attachments.
Post by Joseph on May 5th, 2009, 10:10am

Thank you very much for pointing that out.

I'm sure that will come in handy sooner or later for me. No doubt for others! grin

Perhaps this page might help those wishing to send from another email address: http://www.emailaddressmanager.com/tips/mail-settings.html
Re: Send email, with optional attachments.
Post by Alyce Watson on May 5th, 2009, 10:17am

Thanks, Joseph. I've added that link to the page. I know it will be very useful to the folks who take advantage of this program.
Re: Send email, with optional attachments.
Post by metro on May 5th, 2009, 2:10pm

Yet another option grin

Blat is a Win32 command line utility that sends eMail using SMTP or post to usenet using NNTP.

http://www.blat.net/
Re: Send email, with optional attachments.
Post by stefanhes on Nov 1st, 2009, 12:07pm

* So I downloaded sendEmail-v156
* I copied alyce example program
* I changed it to my gmailaddress and password
* changed the paths
* I even tried 465 instead of 587

It doesn't work.

Can someone help me? Need more info?



Stefan Hesseling


Re: Send email, with optional attachments.
Post by Alyce Watson on Nov 1st, 2009, 1:12pm

on Nov 1st, 2009, 12:07pm, stefanhes wrote:
* So I downloaded sendEmail-v156
* I copied alyce example program
* I changed it to my gmailaddress and password
* changed the paths
* I even tried 465 instead of 587

It doesn't work.

Can someone help me? Need more info?



Stefan Hesseling



Do you have copies of both files in the program folder?



Quote:
'requires sendemail.exe and sendemail.pl


Re: Send email, with optional attachments.
Post by stefanhes on Nov 1st, 2009, 1:29pm

I even made two copies of sendemail.exe and sendemail.pl in the same folder as the .bas folder

no effect (even no error-message)

Here is my code (except for the password, ;-)

Code:

'Example to send email using gmail.
'For other services, see their documentation

'requires sendemail.exe and sendemail.pl

from$ = "rietveldlyceumbrief@gmail.com"
mailuser$ ="rietveldlyceumbrief@gmail.com"
recipient$ ="sjmhesseling@hotmail.com"
server$ = "smtp.gmail.com:587"           '465 of 587
mailpwd$ = "********"
subject$ = "Is dit de titel van het onderwerp"
message$ = "Hallo wereld."
attach$ = "C:\Documents and Settings\Eigenaar\Mijn documenten\Mijn teksten\arbaclassic.txt"

cmd$ = " -f ";from$;" -t ";recipient$;" -s ";server$;" -xu ";mailuser$;" -xp ";mailpwd$;" -u ";subject$;" -m ";message$;" -a ";attach$

run "C:\Documents and Settings\Eigenaar\Mijn documenten\Downloads\sendEmail-v156\"+"sendemail.exe ";cmd$ , HIDE

end


 

Re: Send email, with optional attachments.
Post by stefanhes on Nov 2nd, 2009, 10:30am

Anyone got this working?

Shall I make a new gmail account, make even the password public and can someone send an email with the little program above?
Re: Send email, with optional attachments.
Post by Stefan Pendl on Nov 2nd, 2009, 3:02pm

Have you already tried the -l switch to create a log file?

Is the port open for sendEmail by the firewall?

Do you use the TLS enabled windows version?

Re: Send email, with optional attachments.
Post by stefanhes on Nov 2nd, 2009, 4:43pm

Thank you Stefan!!

I made a logfile.

I saw the problem!!

It was the old MS_DOS not liking spaces in the path name...


Problem solved

thank you again to point me to the right direction.
Re: Send email, with optional attachments.
Post by Stefan Pendl on Nov 3rd, 2009, 12:46am

on Nov 2nd, 2009, 4:43pm, stefanhes wrote:
Thank you Stefan!!

I made a logfile.

I saw the problem!!

It was the old MS_DOS not liking spaces in the path name...


Yes, CHR$(34) is getting mandatory these days, you can not access most files without two of them wink

Re: Send email, with optional attachments.
Post by BlueDwarf on Jul 16th, 2010, 2:07pm

Wow this SendEmail program really rocks! Tested it out on my Virgin Mail account and it works like a dream; attachments no problem! smiley
Re: Send email, with optional attachments.
Post by andy1977 on Feb 21st, 2013, 5:06pm

Really hoping somebody can help. I have tried this code, with the 2 files, but all I can get is "runtime error: out of memory:" The .Bas file is saved in the same folder as the files.

On a sidenote, trying to find out what why it wasn't working, I managed to associate .PL files to notepad, but downloaded Perl to associate with instead.

Many thanks in advance, Andrew
Re: Send email, with optional attachments.
Post by Brandon Parker on Feb 21st, 2013, 9:32pm

Andrew,

Welcome to the forum!!

Without posting the code that you are using we can only guess as to what may be happening. Please post the code you use and someone will definitely help you out.

{:0)

Brandon
Re: Send email, with optional attachments.
Post by andy1977 on Feb 22nd, 2013, 02:03am

Hi, thank you. It is the same code as above, with me own e-mail details:

Code:
'Example to send email using gmail.
'For other services, see their documentation

'requires sendemail.exe and sendemail.pl

from$ = "andrewraab@btinternet.com"
mailuser$ ="andrewraab@btinternet.com"
recipient$ ="jemmaraab@btinternet.com"
server$ = "mail.btinternet.com:25"           '465 of 587
mailpwd$ = "*********"
subject$ = "howdy"
message$ = "test 123"


cmd$ = " -f ";from$;" -t ";recipient$;" -s ";server$;" -xu ";mailuser$;" -xp ";mailpwd$;" -u ";message$;" -a "

run "C:\Users\Andrew\Desktop\sendEmail\sendEmail.exe ";cmd$, Hide

end
 

Re: Send email, with optional attachments.
Post by Rod on Feb 22nd, 2013, 03:34am

Try dropping the -a since you don't specify an attachment.

Code:
cmd$ = " -f ";from$;" -t ";recipient$;" -s ";server$;" -xu ";mailuser$;" -xp ";mailpwd$;" -u ";message$ 


The rest of it looks to be correct.
Re: Send email, with optional attachments.
Post by andy1977 on Feb 22nd, 2013, 3:13pm

Thanks for the reply. That definitely makes sense, so I have corrected the error.

Code:
'Example to send email using gmail.
'For other services, see their documentation

'requires sendemail.exe and sendemail.pl

from$ = "andrewraab@btinternet.com"
mailuser$ ="andrewraab@btinternet.com"
recipient$ ="jemmaraab@btinternet.com"
server$ = "mail.btinternet.com:25"           '465 of 587
mailpwd$ = "**********"
subject$ = "howdy"
message$ = "test 123"


cmd$ = " -f ";from$;" -t ";recipient$;" -s ";server$;" -xu ";mailuser$;" -xp ";mailpwd$;" -u ";message$

run "C:\sendEmail\sendEmail.exe ";cmd$ , Hide

end 


Unfortunately I am still getting the error, "Runtime error: Out of memory". Below is the error log, If you don't mind, and have the time to have a look. Thanks (I didn't put in the smiley faces lol)
Code:
Error log timestamp Friday 22/02/13 20:50:20

Runtime error: out of memory

Error(Exception)>>defaultAction
Error(Exception)>>activateHandler: <anUndefinedObject> 
Error(Exception)>>handle
Error(Exception)>>signal
Error class(Exception class)>>signal: <'out of memory'> 
BasicProgram(Object)>>error: <'out of memory'> 
BasicProgram>>terminateRun: <anError> 
[] in BasicProgram>>errorHandlerBlock
ExceptionHandler>>evaluateResponseBlock: <aBlockClosure> for: <anError> 
[] in ExceptionHandler>>handle:
ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> 
BlockClosure>>invisibleEnsure: <aBlockClosure> 
ExceptionHandler>>handle: <anError> 
ExceptionHandler>>findHandler: <anError> 
Error(Exception)>>activateHandler: <anExceptionHandler> 
Error(Exception)>>handle
Error(Exception)>>signal
Error class(Exception class)>>signal: <'out of memory'> 
BasicProgram(Object)>>error: <'out of memory'> 
[] in RunCommand>>using:
[] in BasicProgram>>begin
ExceptionHandler>>evaluateProtectedBlock: <aBlockClosure> 
[] in ExceptionHandler>>activateDuring:
ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> 
BlockClosure>>invisibleEnsure: <aBlockClosure> 
ExceptionHandler>>activateDuring: <aBlockClosure> 
ExceptionHandler class>>handle: <anError class> with: <aBlockClosure> during: <aBlockClosure> 
BlockClosure>>on: <anError class> do: <aBlockClosure> 
BasicProgram>>begin
BasicProgram>>run
[] in BasicSourcePane>>run
BasicCompiler class>>compileFromString: <'
''Example to send e...'> notify: <aBasicSourcePane> ifSuccess: <aBlockClosure> 
BasicSourcePane>>run
BasicSourceWindow>>run
BasicEditorModel>>run: <aToolbarButton> 
BasicEditorModel(Object)>>perform: <#run:> with: <aToolbarButton> 
ToolbarButton>>triggerClickedEvent
Message>>perform
NotificationManager>>runPendingEvents
NotificationManager>>runEventLoop
Message>>perform
Message>>evaluate
Process>>safelyEvaluate: <aMessage> 
Process>>evaluate: <aMessage> 
 


Re: Send email, with optional attachments.
Post by Mattestion on Feb 22nd, 2013, 3:39pm

Nothing in the code you supplied should be giving an out of memory error. It could be something other than LB causing the problem. Have you tried restarting your computer? This will clear the memory and perhaps resolve the problem.
Re: Send email, with optional attachments.
Post by andy1977 on Feb 22nd, 2013, 5:08pm

Getting closer, I think I may have downloaded the wrong sendemail files. I got them from this site: http://caspian.dotconf.net/menu/Software/SendEmail/

and was downloading the 'official' files. Just noticed the files for windows, with TLS Support, downloaded, and now, no more errors. Still struggling to get anything sent through though. Earlier in this thread, someone was successful in sending from a Gmail account, so have now changed my 'from e-mail address', to a gmail.
and got the smtp details from here:
http://www.emailaddressmanager.com/tips/mail-settings.html

Code:
 from$ = "andrewstuartraab@gmail.com"
mailuser$ ="andrewstuartraab@gmail.com"
recipient$ ="andrewraab@btinternet.com"
server$ = "smtp.gmail.com:587"           '465 of 587
mailpwd$ = "*******"
subject$ = "howdy"
message$ = "test 123"


cmd$ = " -f ";from$;" -t ";recipient$;" -s ";server$;" -xu ";mailuser$;" -xp ";mailpwd$;" -u ";message$

run "C:\sendEmail\sendEmail.exe ";cmd$ , Hide

end
 


I would like to say a big thank you, to everyone that is taking the time and effort to reply. I do really appreciate it.
Re: Send email, with optional attachments.
Post by Mattestion on Feb 22nd, 2013, 5:23pm

I just remembered that this was recently discussed on the JB forums. See this thread: SENDEMAIL USAGE PROBLEMS

BTW, Reply #7 in that thread has the correct Gmail settings.
Re: Send email, with optional attachments.
Post by Rod on Feb 23rd, 2013, 03:48am

Writing the .log file would seem to be the fastest way to get to the root of the problem. John shows how in the rosetta code example.

http://rosettacode.org/wiki/Send_email#Liberty_BASIC
Re: Send email, with optional attachments.
Post by andy1977 on Feb 23rd, 2013, 8:12pm

Just wanted to let you know, that thanks to your help, tips, and clues in the right direction, I have got it to work. Although not from my btinternet account as planned, but from a gmail account I created in place. It's working, so not going to play around with it lol.

There is just one more query though, and having looked through the forums, I don't think it has been asked. In the main body of the message, I can get my text, but was wondering if part way through, if there was a way to start on a new line for text, like a start of a new paragraph?

Normally for printing on paper, or on screen, I know the lprint command on each new line, but realise this doesn't apply in this case.

If it hasn't already become apparent, I bit of a novice to programming.
Re: Send email, with optional attachments.
Post by Mattestion on Feb 23rd, 2013, 8:57pm

I believe you would need to use the CRLF character (Carriage Return + Line Feed). It's actually a combination of two characters represented as 13 and 10 on the ASCII chart. So for your message you would have something like this: paragraph1$ + chr$(13) + chr$(10) + paragraph2$. Actually I believe to have a blank line between paragraphs you would need two CRLF.
Re: Send email, with optional attachments.
Post by Stefan Pendl on Feb 24th, 2013, 09:48am

SendEmail offers the ability to use the contents of a file as the body with a different command line switch.

So remove the body from the command line and use a body file instead.

The command line is only good for simple messages, like one-liners, more complex ones should be saved to a file anyways.
Re: Send email, with optional attachments.
Post by Brandon Parker on Feb 24th, 2013, 7:06pm

on Feb 24th, 2013, 09:48am, Stefan Pendl wrote:
The command line is only good for simple messages, like one-liners, more complex ones should be saved to a file anyways.


I'm not saying not to use a file for the body, but if you build your body in the program correctly sendEmail will have no problem sending all of the string you give it for the body through the command line. I currently utilize this method for constructing/ sending e-mails out as alerts for a group in my company.

Either way is correct as long as you format it correctly.....


{:0)

Brandon
Re: Send email, with optional attachments.
Post by Stefan Pendl on Feb 25th, 2013, 2:57pm

The length of the command line is limited, so using files for long strings is rational.

The command line limitation is laid on us by Windows, so there is nothing we can do to overcome it.
Re: Send email, with optional attachments.
Post by Rui Branco on Jan 14th, 2014, 11:59am

Something changed in gmail service, now we need TLS to send email with this code.
Can anyone confirm?
Re: Send email, with optional attachments.
Post by Rui Branco on Jan 14th, 2014, 12:28pm

Code:
text$       = "This is a simple text message."
tls$        = "tls=yes"
from$       = "xx@gmail.com"
username$   = "xx@gmail.com"
password$   = "xxx"
recipient$  = "xx@gmail.com"
server$     = "smtp.gmail.com:587"
subject$    = chr$( 34) +text$          +chr$( 34)  '   Use quotes to allow spaces in text.
message$    = chr$( 34) +"Hello world." +chr$( 34)
attach$     = "CHANGELOG.txt"
logfile$    = "sendemail.log"

cmd$ = " -o ";  tls$;_
       " -f ";  from$;_             'from
       " -t ";  recipient$;_        'to
       " -u ";  subject$;_          'subject
       " -s ";  server$;_           'server
       " -m ";  message$;_          'message
       " -a ";  attach$;_           'file to attach
       " -l ";  logfile$;_          'file to log result in
       " -xu "; username$;_         'smtp user name
       " -xp "; password$           'smtp password not given so will ask in a CMD window

run "sendEmail.exe "; cmd$, HIDE

end

 


output
Jan 14 18:24:33 x-pc sendEmail.exe[8076]: ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)

Re: Send email, with optional attachments.
Post by Stefan Pendl on Jan 14th, 2014, 6:09pm

SendEmail does support TLS, but it is a separate download.

Also make sure to have the latest SendEmail.exe downloaded from the original home page at http://caspian.dotconf.net/menu/Software/SendEmail/
Also check out the TLS support section of the download page, which tells you what you need to install in addition.
Re: Send email, with optional attachments.
Post by andy1977 on Jan 18th, 2014, 5:39pm

Thanks for the heads-up on that. I'm still using my original program from a year ago, which seems to be still working fine with e-mails, so thinking I may already be using the TLS. (I hope so anyway, I still remember the headache it gave me last time to get it working)
Re: Send email, with optional attachments.
Post by Rui Branco on Jan 19th, 2014, 10:52am

on Jan 18th, 2014, 5:39pm, andy1977 wrote:
Thanks for the heads-up on that. I'm still using my original program from a year ago, which seems to be still working fine with e-mails, so thinking I may already be using the TLS. (I hope so anyway, I still remember the headache it gave me last time to get it working)


I can not get it to work with the version that supports tls even install the Net SLeay and IO Socket SSL perl modules, was forced to use another application http://libertybasic.conforums.com/index.cgi?board=internet&action=display&num=1389742483
Re: Send email, with optional attachments.
Post by YACKARE on Aug 7th, 2017, 08:45am


I have a program to distribute it between unknown users and I would like to be sent an email to my fixed email address. I suppose sendemail does not serve me because I would have to know the unknown user's server. I'm right? Is there any way to solve this problem?