Page 1 of 2
Email from within a program
Posted: Mon Jan 21, 2019 9:32 pm
by PaulKnight
Hi,
I am very new to Smart Basic. I dabbled a few years ago, but didn't really have a problem to solve so didn't have much motivation to learn - and was also very busy!!
However, I now have a need for a custom apps, so am trying again.
I just wondered if it was possible to send an email from within your code?
Once my program has calculated and generated output, I'd like to send the results directly to an email address. Do you know if this is possible please?
Any help much appreciated.
Many thanks,
Paul.
Re: Email from within a program
Posted: Mon Jan 21, 2019 10:13 pm
by rbytes
Yes, I posted a program with that feature last April, called SB Notes.
viewtopic.php?f=20&t=2179
Check it out, and look for the action that occurs when the Mail button is pressed. You can copy the code from that section.
Let me know if you need further help.
Oh yes, Happy New Year, and welcome to the Forum.
Re: Email from within a program
Posted: Thu Jan 24, 2019 9:34 am
by GeorgeMcGinn
Ever since my last post (I had a real rough several months after I moved) so I was in no condition to really evaluate it, but afterwards I have had the time and this is the best programs on how to create and send marked-up HTML emails, where if you tried to do this in the iCloud email App, you cannot do many of the things this program does.
This one (SB Notes) is a keeper. Version 1.1 is a souped up version of the first version, but both preform creating the emails the same. I think the first version was an attempt to print from SmartBASIC by using an email address that may be directed to a printer (at least that is what it looks like).
Re: Email from within a program
Posted: Fri Jan 25, 2019 10:34 pm
by PaulKnight
Thanks for this link RBytes.
I must admit, I was expecting it to be a bit simpler than this - I'm going to have to really study your code to get to the nitty gritty bits that do the actual sending, as I only really want to send a simple string to a single email address. Plain text, no images or formatting etc...
I recall using TechBasic at some point and assumed it would be a similar approach in SB (e.g. something like system.newEmail("
xxxx@yahoo.co.uk"),message$
Nevermind, I love SB now, so I'll persevere!
Many thanks
Re: Email from within a program
Posted: Fri Jan 25, 2019 11:08 pm
by rbytes
The technique requires more than just a single line of code, because it calls JavaScript in a Smart Basic browser window. But no need to reinvent the wheel. Everything you need is here.
Try this code. Substitute your own choice of email, subject and body in the first 3 lines. Then run the program. It will open a new Mail message with the address, subject and body, all ready to press Send.
Code: Select all
email$="somebody@somewhere.ca"
subject$="Your Kijiji ad"
body$="I am interested in your 76 Mustang. Will you negotiate on the price?"
a1$="<html><head><script type="&q$&"text/javascript"&q$&"> function mymessage() { location.href="
a1a$=CHR$(34)&"mailto:"
a1b$=email$!a1c$="?subject="
a2$=subject$
a3$="&body="
a4$=body$
a5$=CHR$(34)&";} </script></head><body onload="&q$&"mymessage()"&q$&"></body></html>"
a$=a1$&a1a$&a1b$&a1c$&a2$&a3$&a4$&a5$
BROWSER "n" AT 0,0 SIZE 100,100
BROWSER "n" TEXT a$
end
Re: Email from within a program
Posted: Sat Jan 26, 2019 7:22 am
by Henko
Can you actually send the email from within the SB program without touching the "send" button? That would be a nice feature to mail a selected group of contacts from a contacts base.
Re: Email from within a program
Posted: Sat Jan 26, 2019 2:28 pm
by rbytes
I haven't found a way to do that yet. It might be possible with JavaScript, so I will keep looking.
Re: Email from within a program
Posted: Sun Jan 27, 2019 10:30 am
by PaulKnight
Hi,
Thank you so much for this! I must admit, I don't really understand the code but it is doing exactly what I wanted so it's very helpful, and much appreciated.
Re: Email from within a program
Posted: Sun Jan 27, 2019 2:40 pm
by rbytes
You're welcome, Paul. The code does look confusing at first. Basically, you have to construct a short HTML web page that will call a JavaScript email command. The structure of the page never changes, but some of the elements do - the email address, the subject and the body (contents). So I make each element a text string. Once the user inserts the three variable elements, I reassemble the strings to create the complete page.
Try adding the line PRINT a$ at the end of the program and you will see the complete HTML page.
Re: Email from within a program
Posted: Sun Jan 27, 2019 9:55 pm
by rbytes
Paul, I just posted a new topic called The End of Smart Basic? in Other Topics.
You mentioned that you might be using it in a new project. You and other new users need to be aware of the current shaky status of Smart Basic, and not put unrealistic hopes on it. If the success of your project will affect either your finances or your career success, please read my post ASAP.