Since I couldn't find a complete solution anywhere else, I thought I'd make a post about how to send mail using Gmail SMTP, Zend Mail and Xoauth2.
First, you need to put a file called Xoauth.php in Zend/Mail/Protocol/Smtp/Auth. The contents of the file are as follows:
require_once 'Zend/Mail/Protocol/Smtp.php';
class Zend_Mail_Protocol_Smtp_Auth_Xoauth extends Zend_Mail_Protocol_Smtp
{
protected $_xoauth_request;
public function __construct($host = '127.0.0.1', $port = null, $config = null)
{
if (isset($config['xoauth_request'])) {
$this->_xoauth_request = $config['xoauth_request'];
}
parent::__construct($host, $port, $config);
}
public function auth()
{
parent::auth();
$this->_send('AUTH XOAUTH2 ' . $this->_xoauth_request);
$this->_expect(235);
$this->_auth = true;
}
}
If you're curious about how this file gets called, look in Transport/Smtp.php for the _sendMail function. The variable connectionClass is what defines the file location.
Now to actually send the email you need the following code:
require_once 'Zend/Mail/Transport/Smtp.php';
require_once 'Zend/Mail.php';
function constructAuthString($email,$accessToken) {
return base64_encode("user=$email\1auth=Bearer $accessToken\1\1");
}
function sendEmail($email,$accessToken){
$smtpInitClientRequestEncoded = constructAuthString($email, $accessToken);
$config = array('ssl' => 'ssl',
'port' => '465',
'auth' => 'xoauth',
'xoauth_request' => $smtpInitClientRequestEncoded);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
$mail->setBodyText('some body text');
$mail->setFrom($email, 'Some Sender');
$mail->addTo("email of recipient", 'Some Recipient');
$mail->setSubject('Test sending by smtp');
$mail->send($transport);
}
Call sendEmail() with the arguments email and accessToken and you'll be sending an email with Gmail SMTP and XOauth!
Note: I'll put this stuff on Github in a bit.
The PieceWise Blog
Sunday, February 3, 2013
Monday, September 24, 2012
Autumn's in the air
We have recently added many drink recipes to our Recipes Project and to fit the changing of the seasons, we have one particular recipe we'd like to share. With a few simple ingredients, you can make a delicious Autumn Punch, enriched with cinnamon and apple cider.
PieceWise also has a new option for users--the ability to stay logged in. On the Login Page, simply click the "Keep me logged in" box directly underneath where you enter your user information.
Thursday, September 20, 2012
New Recipes and Keeping Them Organized
Recently, the following recipes have been added to PieceWise:
With so many recipes, it's becoming difficult to keep track of all the ones you want to try. This is where PieceWise really shines--organization. While each recipe is its own individual project, they can all become pieces in one general recipe project. Check our recipe project to see all the recipes in one, centralized location.
Friday, September 14, 2012
General Tso's Chicken
Today's recipe will surely leave your stomach pleased--General Tso's Chicken. This is a favorite Chinese meal that would be great (and easy to make) to have this weekend. You can find the recipe here.
In the next few weeks read about more delicious recipes and also a new feature coming to PieceWise--the ability for services to instantly offer their goods to consumers.
In the next few weeks read about more delicious recipes and also a new feature coming to PieceWise--the ability for services to instantly offer their goods to consumers.
Thursday, September 13, 2012
International Haus of Salad
When people think of salad, they typically think of the traditional, plain house salad--possibly Caesar salad if they're feeling a bit risky. Below is a list of 12 different salad types. While house and Caesar salad made the cut, the list includes more festive salads from both domestic and international origins.
The 12 salads featured today are as followed:
Even if you're not typically a salad person, one of these amazing recipes will surely hit the right spot in your stomach. Enjoy the salad alone or serve with your favorite meal.
The 12 salads featured today are as followed:
- Arabic Salad
- Caesar Salad
- Caprese Salad
- Chinese Chicken Salad
- Cobb Salad
- Fruit Salad
- Greek Salad
- House Salad
- Mandarin Orange Salad
- Panzanella Bread Salad
- Strawberry and Feta Salad
- Vegetable Salad
Even if you're not typically a salad person, one of these amazing recipes will surely hit the right spot in your stomach. Enjoy the salad alone or serve with your favorite meal.
Mamma Mia, Pizza Pia!
Perhaps the best food on the planet and most popularly agreed on choice for lunch would be none other than but pizza! Even when the pizza doesn't turn out so well, it's still a mighty good meal. It's no wonder that with pizza being such a star it'd make its debut on PieceWise--and that's exactly what it's done, in style.
Instead of listing off one or two favorite pizza types, PieceWise has compiled the recipes to the top dozen most popular pizzas. Wondering what they are? Here's the list:
See your favorite pizza on the list? Bake it and let us know how the recipe is! If, by chance, your choice didn't make the cut, create a new project listing the type and what steps we need to take to taste the yummy goodness.
Wednesday, September 12, 2012
Appetizer Galore!
Today I have three delicious appetizer recipes that will surely please your taste buds. The first one is a classic favorite, mozzarella sticks. This is certainly a treat sure to fill you up or bring joy to the entire group.
The second appetizer is often overlooked but will certainly leave your stomach happy. Here we have found one of the best recipes to make spinach and artichoke dip. With this appetizer, you'll get both a mouthful of deliciousness and make your mother happy by eating your spinach!
I've saved perhaps the best recipe for last--smoked mozzarella fonduta. Served with baked Italian bread and garnished with diced tomatoes and parsley, this appetizer is a one-hit-wonder. Once you have a sample of this delight you'll beg for more.
Try these recipes out for yourself and let us know what you think!
The second appetizer is often overlooked but will certainly leave your stomach happy. Here we have found one of the best recipes to make spinach and artichoke dip. With this appetizer, you'll get both a mouthful of deliciousness and make your mother happy by eating your spinach!
I've saved perhaps the best recipe for last--smoked mozzarella fonduta. Served with baked Italian bread and garnished with diced tomatoes and parsley, this appetizer is a one-hit-wonder. Once you have a sample of this delight you'll beg for more.
Try these recipes out for yourself and let us know what you think!
Subscribe to:
Posts (Atom)