Retrieving email-id from database and send mail to them - yii

In yii i am creating sendemail functionality. I am using mailer extension and its working correctly after making all settings of SMTP. i had made method actionEmail in controller as-
public function actionEmail()
{
$model=new User;
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->IsSMTP();
$mailer->IsHTML(true);
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
$mailer->Port = 465;
$mailer->CharSet = 'UTF-8';
$mailer->Username = "abc#gmail.com";
$mailer->Password = "abc";
$mailer->From = "xyz#gmail.com";
$mailer->FromName = "Balaee.com";
$mailer->AddAddress('shilpa.kirad#shailani.com');
$mailer->Subject = "welcome to Balaee";
$mailer->IsHTML(true);
// $html = $this->renderPartial('myview',array('content'=>'Hello World'),true);
$mailer->Body = "Welcomeclick on link for other detail ".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($mailer->Send()) {
echo "Please check mail";
//Yii::app()->user->setFlash('register','Thank you for contacting us. We will respond to you as soon as possible.');
// $this->refresh();
}
else {
echo "Fail to send your message!";
}
}
This method is implementing correctly.It is sending mail to address which is mentioned in mailer->AddAdress.But now i want to retrive email id's from database corresponding to specific user's id and send mail to him. i.e.I dont want to insert hard coded value for this field. So how can i do this. Please help me.

for fetch use id of user to get email address as
$user_model=User::model()->findByPk($id);
and set in email as
$mailer->AddAddress($user_model->email_id);
where id and email_id are the table column name.
check other ways .
http://www.yiiframework.com/doc/guide/1.1/en/database.dao

For this to be done, you can fetch email id from database using following query:
$email = SELECT email FROM USER WHERE user_id = "X";
Here X is user_id of user whom you want to send email.
And provide this $email in the receipient's email field. Thanks.

Related

var = emailAddress ... Not in message TO field

The script I am sharing is not passing the emailAddress variable to the message window, when the Email Journal button is selected. Where is this script going wrong with collecting the address and creating the correct variable?
This is the script:
https://raw.githubusercontent.com/mikeamelang/learning-journal/master/Learningjournal.js
Here is setting the variable:
var emailAddress = ' ';
Here is where the address is collected:
// Email address to which the journals will be emailed
if ( a.innerText.substring(0,emailAddressLabel.length) == emailAddressLabel ) {
emailAddress = a.innerText.substring(emailAddressLabel.length).trim();
}
Here is the function to send the email (the subject appears in the message window)
window.open('mailto:' + emailAddress + '?subject=My Learning Journal&body=' + contents);
I was expecting the email address to appear in the TO field of the message window. The only thing that fills in is "Add your email here"

Twilio Programmable Voice isn't working

When i try to pass param from my application using [TwilioVoice Call] method i am not able to get those param on twiML application. but when i try to pass same data from POSTMAN with FormData its working fine and also successfully able to create call.
Would you please help me how can i use param passed from my iOS application into twiML
TwiML Application in PHP :
<?php
/*
* Makes a call to the specified client using the Twilio REST API.
*/
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_GET["to"]) ? $_GET["to"] : "";
if (!isset($to) || empty($to)) {
$to = isset($POST["to"]) ? $_POST["to"] : "";
}
$from = isset($_GET["from"]) ? $_GET["from"] : "";
if (!isset($from) || empty($from)) {
$from = isset($POST["from"]) ? $_POST["from"] : "";
}
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
iOS Objective-C :
self.call = [TwilioVoice call:[self fetchAccessToken]
params:#{#"to": #"1",#"from":#"2"}
uuid:uuid
delegate:self];
Twilio Error Log when i try to pass param from iOS
Warning - 13224 Dial: Twilio does not support calling this number or the number is invalid
Reference TwiML Application Code
https://github.com/twilio/voice-quickstart-server-php
Twilio developer evangelist here.
The 12100 error comes from Twilio not being able to parse the TwiML returned from your server. In this case, it is because your PHP is not returning TwiML, it's trying to make a call using the REST API.
It should return a <Dial> with a nested <Client>. You can build this up using the helper library too. Try changing your code to this:
<?php
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_REQUEST["To"]) ? $_REQUEST["To"] : "";
$to = str_replace("client:", "", $to);
$from = isset($_REQUEST["From"]) ? $_REQUEST["From"] : "";
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
Let me know if that helps.
Step 1. In the name you have to pass name of the user(any thing you want)
Step 2. You need to generate token using 3 parameters
Step 3. You need to create object of VoiceGrant
Step 4. You need to pass Id
Step 5. You need to set PUSH notification Id generate from twilio
$name = $this->input->post('name');
//$PUSH_CREDENTIAL_SID = 'CRaf1a66dd4a7656876e16c7820ef5c01e';
$outgoingApplicationSid = 'APf9b1b789ba690b8789d95a42511f2018';
// choose a random username for the connecting user
$identity = $name;
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$this->twilioAccountSid,
$this->twilioApiKey,
$this->twilioApiSecret,
3600,
$identity
);
// $chatGrant = new ChatGrant( $pushCredentialSid= "CRaf1a66dd4a7656876e16c7820ef5c01e");
//
// print_r($chatGrant);die;
// Create Chat grant
// $voiceGrant = new VoiceGrant($serviceSid = 'IS840a7e5f64634ab6bf179c3f8b0adfc4',$pushCredentialSid = 'CRaf1a66dd4a7656876e16c7820ef5c01e');
$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
// Optional: add to allow incoming calls
$voiceGrant->setIncomingAllow(true);
$voiceGrant->setPushCredentialSid('CRaf1a66dd4a7656876e16c7820ef5c01e');
// Add grant to token
$token->addGrant($voiceGrant);
// render token to string
$voice_token = $token->toJWT();
if($voice_token){
$data['token'] = $voice_token;
$this->response = array('status'=>1,'data'=>$data);
}else{
$this->response = array('status'=>0,'message'=>'Not found');
}

sending email to multiple accounts using php ews

The below code is used for sending email using jamesiarmes/php-ews
in my application
$request = new \jamesiarmes\PhpEws\Request\CreateItemType();
$request->MessageDisposition = "SendOnly";
$request->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
$request->Items->Message->ItemClass = "IPM.Note";
$request->Items->Message->Subject = "exchange new mail";
$request->Items->Message->Body->BodyType = 'HTML';
$request->Items->Message->Body->_ = "This is a test mail as a part of exchange settings set up ";
$request->Items->Message->ToRecipients->Mailbox->EmailAddress = "rejith.rj#pitsolutions.com";
$response = $this->app['ews']->CreateItem($request);
But the problem is I can add only one email address as recipient, how can I add multiple email addresses in ToRecipients?
I checked out the php-ews documentation. You can create an array with multiple recipients this way:
$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = 'john.harris#domain.com';
$toAddresses[0]->Name = 'John Harris';
$toAddresses[1] = new EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = 'sara.smith#domain.com';
$toAddresses[1]->Name = 'Sara Smith';
And then add it to your object like this:
$request->Items->Message->ToRecipients = $toAddresses;
Try this and feedback me please.
Seems to me that your problem has not been solve yet?
Following works for me:
$toAddresses = array();
$toAddresses[0]="test#test.com";
$toAddresses[1]="test2#test.com";
$api = MailAPI::withUsernameAndPassword("server", "username", "password");
$message = new Type\MessageType();
$message->setBody('Some Text');
$message->setSubject('Test Subject');
$message->setToRecipients($toAddresses);

Using Google Apps script, how to check if an email has a pdf attached to it, then forward it to another email address?

I managed to create a function that converts an email to a pdf and then it forwards it to another email address ( I used this great library made by Mike Greiling :https://github.com/pixelcog/gmail-to-pdf).
but now I want to create another function that checks if the email already has an attachment, and then forward it right away.
here's my working function:
function saveExpenses() {
GmailUtils.processStarred( 'label: test', 5, function(message) {
// create a pdf of the message
var pdf = GmailUtils.messageToPdf(message);
// prefix the pdf filename with a date string
pdf.setName(GmailUtils.formatDate(message, 'yyyy/MM/dd - ') + pdf.getName());
// send confirmation email to the original sender
var confirmationEmail = message.getFrom();
// Get the name of the document to use as an email subject line.
var subject = pdf.getName();
var body = "This is a confirmation that this receipt has been sent";
// Send a confirmation email to the sender
GmailApp.sendEmail(confirmationEmail, subject, body, {attachments: [pdf]});
return true;
});
}
}
Ok, I found the solution, actually it was pretty easy.
I guess I didn't think enough, so basically I just get all the attachments from the message with the function getAttachmentswhich returns an array of attachments, I then just check if the length of the array is greater than 0 ( which means there are attachments in the email )
and if the result is 0, it means there are no attachments.
Here is what I did :
var attachment = message.getAttachments();
if (attachment.length > 0 ) {
// I add the code to deal with the attachment
} else if (attachment.length == 0 ) {
// I add the code that I posted in the question above
}

How to email SalesForce users temporary password by using API?

I am using SOAP Partner API and I have a Developer edition. I am creating users by using API. And upon creation of users I want to email these users temporary password which they can use to login to SalesForce.
This is my code:
SaveResult[] results = connection.create(new SObject[] { user });
if (results[0].isSuccess())
{
out.println("Created user: " + results[0].getId());
//connection.setPassword(results[0].getId(), "password");
ResetPasswordResult rpr = connection.resetPassword(results[0].getId());
String result = rpr.getPassword();
System.out.println("The temporary password for user ID " + results[0].getId()
+ " is " + result);
}
else
{
out.println("Error: " + results[0].getErrors()[0].getStatusCode() +
":" + results[0].getErrors()[0].getMessage());
}
This is the output I am getting in console:
The temporary password for user ID 005E0000000MwkZIAS is ucQD2PADs
However, the user is NOT receiving any password. :-(
Thanks,
Wap Rau
If you build & pass an EmailHeader in your soap request you can control what types of emails will get sent from your request.
It looks like you're using WSC, so you can add this call before calling resetPassword, which will enabled emails being sent to users. This should then send the standard reset password email.
connection.setEmailHeader(false, false, true);
use this class to send out an email. include the pwd variable in the string you want to send the user. there's an example that spells everything out
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm