Send email via GMail SMTP in REBOL 2 - gmail

I am new to REBOL. People blogging about how great REBOL is used sending an email as an example, similar to this example from the "send" documentation:
send luke#rebol.com "Testing REBOL Function Summary"
having read how easy and convenient it is to do this, I excitedly tried to send myself a test email via my GMail account.
I looked at the official GMail help for SMTP/POP to get the relevant SMTP/POP server names:
https://support.google.com/mail/answer/7104828?hl=en
And here is how far the "send" and "set-net" documentation got me:
>> set-net [ myrealusername#gmail.com smtp.gmail.com pop.gmail.com ]
>> send myrealusername#gmail.com "Hello me!"
connecting to: smtp.gmail.com
** Access Error: Cannot connect to smtp.gmail.com
** Where: open-proto
** Near: smtp-port: open [scheme: 'esmtp]
either only
On reflection, of course it didn't work; I told REBOL nothing about wanting to use SSL/TLS, the relevant port numbers, or my GMail password. It must need all of the above to actually send an email.
So how do I do it?

I modified the protocols some years ago to work with gmail. I hope that they still work.
You'll need to run both the prot-ssmtp.r and prot-ssend.r, and you'll need a version of rebol2 which supports ssl. This is either a free view build, or a paid core build.
do https://raw.githubusercontent.com/gchiu/Rebol2/master/Protocols/prot-ssmtp.r
do https://raw.githubusercontent.com/gchiu/Rebol2/master/Protocols/prot-ssend.r
Now, you can either set the user and password manually:
system/schemes/esmtp/user: "username"
system/schemes/esmtp/pass: "password"
or, when the script runs the very first time, you will be asked the values so that they can be set for that rebol instance. The prot-ssmtp uses port 465 but you can modify that if it's no longer correct.
And then it should be as straight forward after setting set-net as:
ssend email#someon.com "This is my message"
Note that we now have email on ren-c which is the open source fork of rebol3.

Related

Is there a way to send the verification email with the Firebase Admin SDK from my Node.js server?

Is there a way to send the email verification email from my server ?
This is how it's done on the client:
authData.sendEmailVerification().then(function() {
Is there a way to do it on the server ?
firebaser here
To my surprise there currently is no option to send verification email from within the Admin SDK. I'd recommend you file a feature request.
What you can do from the Admin SDK is update a user profile to mark their email as verified. This allows you to take control of the entire verification flow if you want to, finishing with a call to admin.auth().updateUser(...) (on Node.js, see the link for other supported languages).
I just came across the same problem as you. There is a function to generate the verification link using user's email address.
I used this function on an array of email addresses, then load the result to my mail automation API to send mails out. This function is weirdly not documented:
admin.auth().generateEmailVerificationLink([EMAIL_ADDRESS])
You can use :
axios.post('https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[API_KEY]',
{ requestType: 'VERIFY_EMAIL', idToken: response.data.idToken }
)
https://firebase.google.com/docs/reference/rest/auth#section-send-email-verification

Architechting webmail app on cpanel host: How do I go about tying in the actual email service?

Im in the process of constructing a Webmail SPA, similar to Gmail, for end users. This app will be hosted on a cPanel shared hosting (LAMP stack). The end users have no cpanel email access otherwise. My app will be their access portal for these email accounts.
If it matters, I'm preferably a node developer, with LAMP experience, so I'm open to any broad suggestions. Note, normally im just bouncing things out, using smtp. Would i just do this straight Imap? I just want to know on an architectural level what service i need to be accessing, or looking for and maybe a point in the direction of some example.
Maybe a wire-frame, a flowchart, or a sentence that can describe how I can implement it will suffice. I can find the technologies, I just need a road map.
This is a RHEL6
$ uname -a
Linux 2.6.32-604.30.3.lve1.3.63.el6.x86_64 #1 SMP Sun Sep 27 06:34:10 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
Some questions based on the only way im able to think about this problem:
What protocol normally accesses the email (user?) Would i be getting something, maybe an internal mail command access from system environment variables, or PATH maybe? Would i ping for a user list, i mean what information does the app need to connect to the mail server, and what protocol would i get that from? I think this is my hitch.
I guess the first thing, is during post, it auths, what happens after auth, what protocol, where/what will i be looking to make that decision based on, and how do i pull in the email list after? Im guessing this is just an IMAP requst. Is that all i need? e.g. php mail() or nodemailer?
Also I cant seem to come up with the proper terminology to get any meaningful google search results, I'm open to search query help as an alternative, not sure what techs I'im looking for yet.
Edit:
On some research i have found the following;
Some search terms that are finally yielding a few results
webmail interfacing php (or node)
webmail single page application node (or php)
Looks like this might be one example of a way a node app connects to an imap
https://github.com/cozy-labs/emails/blob/master/server/imap/pool.coffee
I believe that mail util is here https://www.npmjs.com/package/nodeutil
If someone can help me put this into perspective, that would be great.
Some answers on this:
To roll your own, webmail on a shared host, cPanel API's, curl, fopen, and 3rd party email application apis would be the starting point.
cPanel may not fully support this however they do have apis, UAPI being the most likely for some basic scenarios. https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Email%3A%3Alist_pops
However, Afterligic's WebMail Lite contains a promising looking solution, with a PHP,REST, and JavaScript API. http://www.afterlogic.org/docs/webmail-lite/integration-and-development
The PHP example to read messages looks like it might be this one here
<?php
include_once __DIR__.'/../libraries/afterlogic/api.php';
if (class_exists('CApi') && CApi::IsValid())
{
// data for logging into account
$sEmail = 'user#domain.com';
$sPassword = 'PassWord';
$sFolder = 'INBOX';
$iOffset = 0;
$iLimit = 5;
$oCollection = null;
try
{
$oApiIntegratorManager = CApi::Manager('integrator');
$oAccount = $oApiIntegratorManager->LoginToAccount($sEmail, $sPassword);
if ($oAccount)
{
$oApiMailManager = CApi::Manager('mail');
$oCollection = $oApiMailManager->getMessageList($oAccount, $sFolder, $iOffset, $iLimit);
if ($oCollection)
{
echo '<b>'.$oAccount->Email.':</b><br />';
echo '<pre>';
echo 'Folder: '.$sFolder."\n";
echo 'Count: '.$oCollection->MessageCount."\n"; // $oCollection->MessageResultCount
echo 'Unread: '.$oCollection->MessageUnseenCount."\n";
echo 'List: '."\n";
$oCollection->ForeachList(function ($oMessage) {
$oFrom = $oMessage->From();
echo "\t".htmlentities($oMessage->Uid().') '.$oMessage->Subject().($oFrom ? ' ('.$oFrom->ToString().')' : ''))."\n";
});
echo '</pre>';
}
else
{
echo $oApiMailManager->GetLastErrorMessage();
}
}
else
{
echo $oApiIntegratorManager->GetLastErrorMessage();
}
}
catch (Exception $oException)
{
echo $oException->getMessage();
}
}
else
{
echo 'AfterLogic API isn\'t available';
}
And a
Some other thoughts on rolling your own:
Heres an article shedding light on how to view accounts, using php
How to create an Email Account in Cpanel via PHP?
And one to list
How to access list of email accounts with cPanel API?
A cpanel class was built to provide a way to create and forward, and probably serves as the best example, on a start to the solution. http://sajjadhossain.com/tag/cpanel-class/ resourced from here where lots of testing was done on this topic http://www.zubrag.com/scripts/cpanel-create-email-account.php
To forward emails, in case that's of some use to get them possibly to another temp account
https://www.a2hosting.com/kb/cpanel/cpanel-mail-features/forwarding-incoming-e-mail-messages-to-a-script-file
Then there is the option for squirrel mail or the other two mail apps supported by cpanel: possibly turn one of those into a portal. Here is a way to auth to squirrel mail for e.g. http://squirrelmail.org/plugins_category.php?category_id=6

ec2 node.js server not sending email - any ideas?

I have a website that I'm getting back up after a year+ of being down. I haven't made any code changes, and I've got the site back up and everything is working as before except for the site/app sending email.
It's an ubuntu node.js server. It's hosted on Amazon and I had to create another instance and repoint the dns, etc. An example code snippet that used to work but now doesn't:
var emailServer = email.server.connect({user:"<my gmail>",password:"<mypw>",host:"smtp.gmail.com",ssl:true});
emailServer.send({
text: "Your username is: " + userName + ".",
to: emailAddress,
subject: "Activate Your a2zCribbage Account",
attachment: [...]
}, function(err, message) { if (err) console.log(err); });
When I first tried to send email the gmail account I use got a message "sign-in attempt prevented" Someone just tried to sign in to your Google Account <account> from an app that doesn't meet modern security standards.
I followed what Google said and changed the security to allow apps, but still nothing gets sent.
What am I missing? What other things can I try? Do ec2 severs not just allow email to be sent by default?
Gmail is not a platform for sending automated email. Just because you can doesn't mean it's designed for doing so.
AWS EC2 instances are also problematic for sending email; the ports may be blocked or throttled, you are certainly getting higher spam scores for doing so.
The canonical solution is to use AWS SES. Here's sample code and here's the documentation. There's also a simple third-party library.

oauth2, imap, gmail - fetching mails - gmail api is down and can't find reference to oauth2

I have a requirement (flexible) to use oauth2. (existing architecture/code)
I have a need to do some text manipulation of subscriber's email headers.
Solutions I've tried.
I've tried to download the sample code for java and it correctly connects to gmail's imap servers. It however responds with oath_version=1 and is expecting a password. I've tried to massage the code to change the params as other api's like their Contacts api oauth2 without success.
Question:
(multipart)
Api is down:http://code.google.com/googleapps/domain/email_migration/developers_guide_java.html any reference online would be ideal (it has been down for at least half a week since last week Wed). If you wondered - yes I did post on their forums before asking here for the updated link.
Is there a way to: a) make oauth2 request and b) Any (minimal) code exaples I can look at would be great.
Thanks in advance for reading this post.
Here is a working, Ruby example of fetching email from Google using the OAuth2 protocol:
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', 'example#gmail.com', 'oauth2_access_token_goes_here')
imap.select('INBOX')
imap.search(['ALL']).each do |message_id|
msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
mail = Mail.read_from_string msg
puts mail.subject
puts mail.text_part.body.to_s
puts mail.html_part.body.to_s
end
Note: This example uses ruby mail gem and gmail_xoauth gem, so you will need those installed for this code sample to work. I am also using the omniauth and omniauth-google-oauth2 gems to handle logging the user in and using the access token.

Branding Regular GMail for New Address

So, with Gmail adding support for 3rd party SMTP servers, and my lame work email system supporting email forwarding, the logical thing for me to do was to start a gmail box for my work, forward to it from work, and setup my work SMTP (none of that "sent on behalf of" garbage anymore.)
I figured out how to replace the Gmail logo with my company's logo using a Greasemonkey script, and figured out how to replace the "Loading blah#gmail.com" with "Loading my work#email.com)
What I haven't been able to crack, however, is getting the blah#gmail.com address on the top bar to be 'switched' to my new email address (even if only for show). I used a Replace text script, but apparently it doesnt work on JavaScript (when I ran it on the HTML version, it replaced the text, but who wants to replace the HTML version)
LONG STORY SHORT**: Does anyone know of a way I can, using Greasemonkey or something similar, change what email address displays on the top of my gmail window?** (next to 'Offline | Older Version | Help | Report Gmail bug | Sign OUt')
If you own the domain at your work you can register it with google apps http://www.google.com/apps/intl/en/group/index.html and then set your MX servers to google and use their gmail (with your logos) there.
If you don't own the domain, I would NOT recommend forwarding your company email to gmail. I know my company gets very grumpy when my corpoate email leaves their servers.
Javascript for your solution:
// ==UserScript==
// #name Gmail Replace Domain
// #author http://codejoust.com
// #namespace http://mail.google.com/
// #description example script to alert "Hello world!" on every page
// #include http://mail.google.com/*
// ==/UserScript==
var your_domain = 'yourdomain.com';
var canvas_frame = document.getElementById('canvas_frame').contentWindow.document;
var user_id = canvas_frame.getElementById('guser').getElementsByTagName('b')[0];
user_id.innerHTML = user_id.innerHTML.replace('gmail.com',your_domain);
As a gist.

Resources