Send attachment from s3 bucket using Mailgun - mailgun

Trying to send an email with inline images embed. Only the file is not located on the server it is in an S3 bucket. How can this be done? The standard API doesn't seem to be reading the images into the email.

require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$params = array(
'from' => 'Excited User <YOU#YOUR_DOMAIN_NAME>',
'to' => 'bob#example.com',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!',
'html' => '<html>Inline image: <img src="cid:test.jpg"></html>',
'inline' => array(
array('filePath' => '/path/to/image.jpg'))
);
# Make the call to the client.
$result = $mgClient->messages()->send($domain, $params);
By using inline param you can send the images with the correct path.

Related

Save AWS Polly mp3 file to S3

I am trying to send some text to AWS Polly to convert to speech and then save that mp3 file to S3. That part seems to work now.
// Send text to AWS Polly
$client_polly = new Aws\Polly\PollyClient([
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => [
'key' => $aws_useKey,
'secret' => $aws_secret,
]
]);
$text = 'Test. Test. This is a sample text to be synthesized.';
$voice = 'Matthew';
$result_polly = $client_polly->startSpeechSynthesisTask([
'Text' => $text,
'TextType' => 'text',
'OutputFormat' => 'mp3',
'OutputS3BucketName' => $aws_bucket,
'OutputS3KeyPrefix' => 'files/audio/,
'VoiceId' => $voice,
'ACL' => 'public-read'
]);
echo $result_polly['ObjectURL'];
I'm also trying to accomplish couple other things:
Make mp3 file publicly accessible. Currently I have to go to AWS console to
click "Make Public" button. It seems that 'ACL' => 'public-read' doesn't work for me
I need to return full URL of the mp3 file. For some reason $result_polly['ObjectURL']; doesn't get any value.
What am I missing?
There is no ACL field in the StartSpeechSynthesisTask call:
$result = $client->startSpeechSynthesisTask([
'LanguageCode' => 'arb|cmn-CN|cy-GB|da-DK|de-DE|en-AU|en-GB|en-GB-WLS|en-IN|en-US|es-ES|es-MX|es-US|fr-CA|fr-FR|is-IS|it-IT|ja-JP|hi-IN|ko-KR|nb-NO|nl-NL|pl-PL|pt-BR|pt-PT|ro-RO|ru-RU|sv-SE|tr-TR',
'LexiconNames' => ['<string>', ...],
'OutputFormat' => 'json|mp3|ogg_vorbis|pcm', // REQUIRED
'OutputS3BucketName' => '<string>', // REQUIRED
'OutputS3KeyPrefix' => '<string>',
'SampleRate' => '<string>',
'SnsTopicArn' => '<string>',
'SpeechMarkTypes' => ['<string>', ...],
'Text' => '<string>', // REQUIRED
'TextType' => 'ssml|text',
'VoiceId' => 'Aditi|Amy|Astrid|Bianca|Brian|Carla|Carmen|Celine|Chantal|Conchita|Cristiano|Dora|Emma|Enrique|Ewa|Filiz|Geraint|Giorgio|Gwyneth|Hans|Ines|Ivy|Jacek|Jan|Joanna|Joey|Justin|Karl|Kendra|Kimberly|Lea|Liv|Lotte|Lucia|Mads|Maja|Marlene|Mathieu|Matthew|Maxim|Mia|Miguel|Mizuki|Naja|Nicole|Penelope|Raveena|Ricardo|Ruben|Russell|Salli|Seoyeon|Takumi|Tatyana|Vicki|Vitoria|Zeina|Zhiyu', // REQUIRED
]);
Therefore, you will either need to make another call to Amazon S3 to change the ACL of the object, or use an Amazon S3 Bucket Policy to make the bucket (or a path within the bucket) public.
The output location is given in the OutputUri field (NOT OutputUrl -- URI vs URL).

How to send XML POST request with Guzzle to web service API using Laravel?

I am trying to post a request to my Web API, using Laravel Guzzle Http client. However, I am getting errors trying to post the request. The data I want to send is XML as the API controller is built in XML return format.
I have tried all sorts of methods to post the request with Guzzle but it is yet to work.
public function createProperty(Request $request)
{
$client = new Client();
$post = $request->all();
$create = $client->request('POST', 'http://127.0.0.1:5111/admin/hotel', [
'headers' => [
'Content-Type' => 'text/xml; charset=UTF8',
],
'form-data' => [
'Name' => $post['hotel_name'],
'Address' => $post['address'],
'Phone' => $post['phone'],
'Email' => $post['email'],
'Website' => $post['website'],
'Latitude' => $post['latitude'],
'Longitude' => $post['longitude'],
'Tags' => $post['tags'],
'Priority' => $post['priority'],
'Visible' => $post['visible'],
'Stars' => $post['stars'],
'Description' => $post['description'],
'Facilities' => $post['facilities'],
'Policies' => $post['policies'],
'ImportantInfo' => $post['important_info'],
'MinimumAge' => $post['minimum_age']
]
]);
//dd($create->getBody());
echo $create->getStatusCode();
echo $create->getHeader('content-type');
echo $create->getBody();
$response = $client->send($create);
$xml_string = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $create->getBody());
$xml_string = $create->getBody();
//dd($xml_string);
$hotels = simplexml_load_string($xml_string);
return redirect()->back();
}
I expected the result to POST to the web service and save data to database, but however I got the error "Client error: POST 'http://127.0.0.1:5111/admin/hotel' resulted in a '400 bad request' response. Please provide a valid XML object in the body
Rather than using post-data in the guzzle request, you need to use body:
$create = $client->request('POST', 'http://127.0.0.1:5111/admin/hotel', [
'headers' => [
'Content-Type' => 'text/xml; charset=UTF8',
],
'body' => $xml
]);
$xml will be the XML data you want to send to the API. Guzzle will not create the XML data for you, you'll need to do this yourself.
The XML data can be created using the DomDocument class in PHP.
If you are using Laravel 7+ this simple line should work very well
$xml = "<?xml version='1.0' encoding='utf-8'?><body></body>";
Http::withHeaders(["Content-Type" => "text/xml;charset=utf-8"])
->post('https://destination.url/api/action', ['body' => $xml]);

Unable to get Directory listing of S3 bucket using PHP SDK, EC2

I am using PHP sdk to get list of files in folder form S3.
When I run the php form my localhost, I get the files listing. But when I run the same Php form EC2, it does not work, no error return.
<?php
header('Access-Control-Allow-Origin: *');
require './vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$folderId = $_REQUEST["folderid"];
//echo $folderId;
// Create an S3 client
$client = new \Aws\S3\S3Client([
'region' => 'ap-south-1',
'version' => '2006-03-01',
'credentials' => array(
'key' => 'zzzzzz',
'secret' => 'xxxxxxx',
),
]);
$folderPath = "thumb_images/{$folderId}/";
//echo "<br />".$folderPath."<br />";
$objects = $client->getIterator('ListObjects', array(
"Bucket" => 'bucket_name',
"Prefix" => $folderPath //must have the trailing forward slash "/"
));
foreach ($objects as $object) {
echo $object['Key'] . "<br>";
}
?>

OTRS generic interface rest authentication

I'm trying to consume the OTRS generic interface. The rest service is created by the import functionallity. I found the files needed for import here Consuming OTRS TicketConnector from .NET apps
My problem is when I try to consume the interface for example with a curl command
curl http://<user>:<password>#<server-ip>:<port>/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<Ticket-id> -X GET
The result of the command is
{"Error":{"ErrorCode":"TicketGet.AuthFail","ErrorMessage":"TicketGet: Authorization failing!"}}
I tried every user/password combination that makes sense to me. I tried the otrs admin account, agent account, customer account, root account of the server, EVERYTHING! I can't find a information in the docs that states wich account type is needed.
Here are some information that are printed out by the webservice debugger
Communication sequence started
$VAR1 = {
'DOCUMENT_ROOT' => '/srv/www/htdocs',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' => '*/*',
'HTTP_HOST' => '<server-name>',
'HTTP_USER_AGENT' => 'curl/7.39.0',
'MOD_PERL' => 'mod_perl/2.0.4',
'MOD_PERL_API_VERSION' => '2',
'PATH' => '/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin',
'PATH_INFO' => '/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'PATH_TRANSLATED' => '/srv/www/htdocs/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'QUERY_STRING' => '',
'REMOTE_ADDR' => '<server-ip>',
'REMOTE_PORT' => '56065',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'SCRIPT_FILENAME' => '/opt/otrs/bin/cgi-bin/nph-genericinterface.pl',
'SCRIPT_NAME' => '/otrs/nph-genericinterface.pl',
'SERVER_ADDR' => '<server-ip>',
'SERVER_ADMIN' => '<admin-account>',
'SERVER_NAME' => '<server-name>',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.12 (Linux/SUSE) Server at <server-name> Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.12 (Linux/SUSE)'
};
Deteced operation TicketGet
No data provided
Incoming data before mapping
$VAR1 = {
'RequestMethod' => 'GET',
'TicketID' => '<ticket-id>'
};
TicketGet.AuthFail
TicketGet: Authorization failing!
Outgoing data before mapping
$VAR1 = {
'Error' => {
'ErrorCode' => 'TicketGet.AuthFail',
'ErrorMessage' => 'TicketGet: Authorization failing!'
}
};
Long story short: what type of authentication or user type otrs expects to access the generic interface?
In found my mistake. The way I passed the login credentials to the service was wrong.
In my case the user is a agent user.
Here is a working curl command for my service:
curl http://<server-ip>:<port>/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>?UserLogin=<username>\&Password=<password> -X GET

How to send email notifier with facebook php sdk?

i can do it via url:
https://api.facebook.com/method/notifications.sendEmail?recipients=ID_USER&subject=test&text=test&access_token=USER_ACCESS_TOKEN
http://developers.facebook.com/docs/reference/api/message/
EDIT:
I see now you are trying to use the PHP SDK. Perhaps something like the following will work for you (saw this on another stackoverflow question):
$parameters = array(
'app_id' => $facebook->getAppId(),
'to' => $facebookUserId,
'link' => '(required) The link to send in the message. (??)',
'redirect_uri' => 'URL_TO_REDIRECT_TO_AFTER_USER_CLICKS_SEND_OR_CANCEL',
'picture' => 'OPTIONAL_URL_TO_IMG--AUTOGENERATED BY LINK',
'name' => 'OPTIONAL_NAME_OF_MESSAGE/ARTICLE--AUTOGENERATED BY LINK',
'description' => 'OPTIONAL_DESCRIPTION_TEXT--AUTOGENERATED BY LINK'
);
$url = 'http://www.facebook.com/dialog/send?'.http_build_query($parameters);
echo '<script type="text/javascript">window.open('.json_encode($url).', "_blank", options, false);</script>';