Some question's, and articles I've been reading regarding EML creation
How to verify DKIM signature from an e-mail with openssl?
PHP library to generate EML email files?
https://www.icosaedro.it/phplint/mailer-tutorial/index.html
https://coderedirect.com/questions/25620/php-library-to-generate-eml-email-files (This one is interesting, but it would need extending for DKIM signatures)
https://www.example-code.com/phpExt/smtp_loadEmlAndSend.asp (only does SMTP send)
https://community.apachefriends.org/f/viewtopic.php?t=79968&p=270281 (this works great for Linux, haven't been able to find Windows equivalent)
Use of mailtodisk / mailoutput in XAMPP for Linux (Great concept)
https://swiftmailer.symfony.com/docs/introduction.html (This is from Symfony yet to see if works without Symfony but no longer maintained)
I can't seem to find any standalone class files that will generate the contents for *.eml that can be either stored into file (using file_put_contents) or temporarily into a variable.
The idea is that I can create my *.eml file server-side I could use the contents to verify a DKIM signature, without having to actually send an email.
I did find one library phplint that does what I want, but it is far too big for what I need (635 Files, 53 Folders 7.84 MB (8,224,768 bytes)).
$m = new Mailer();
$m->setSubject("This is the subject");
$m->setFrom("my#mydomain.com", "My Name");
$m->addAddress("you#yourdomain.com", "Your Name");
$m->setTextMessage("This is the text body of the message.");
$m->sendByStream($out_string, TRUE);
$message_as_string = $out_string->__toString();
The above snippet uses the following classes to generate the message.
[180] => it\icosaedro\email\Mailer
[181] => it\icosaedro\io\IOException
[182] => it\icosaedro\utils\StringBuffer
[183] => it\icosaedro\io\OutputStream
[184] => it\icosaedro\io\StringOutputStream
[185] => it\icosaedro\email\Field
[186] => it\icosaedro\email\MIMEAbstractPart
[187] => it\icosaedro\email\Header
[188] => it\icosaedro\email\MIMEPartMemory
[189] => it\icosaedro\email\EOLFilter
[190] => it\icosaedro\utils\Random
I've been looking all over github, as well as PHPClasses. But I can't anything relevant to what I need (with enough research I could probably build it myself but I'd prefer not to reinvent the wheel).
Ideally I'm looking for possibly an extension of PHPMailer, that can stream the EMAIL either to File or String Variable). I also need the class or function to work on both linux and windows.
If somebody can just find a library or point me into the right direction, I'd much appreciate it.
I think I've found what I've been looking for with https://symfony.com/doc/current/mailer.html
$email = (new Email())
->from('hello#example.com')
->to('you#example.com')
//->cc('cc#example.com')
//->bcc('bcc#example.com')
//->replyTo('fabien#example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
echo "<pre>";
print_r($email->toString());
echo "</pre>";
Although I'm still looking for a single class solution rather downloading an bloatware to fulfil a single task.
Related
Im rewriting a few scripts to make use of the new v4 signature for Amazon AWS.
I am trying to send an email using the code on this page:
https://github.com/okamos/php-ses
When I use his code exactly as it is just adding secret keys etc I get an error saying my email address isnt verified on us_east_1. This makes sense as all my things are on EU_WEST_1.
So Ive tried adding the EU endpoint as a third parameter but get this error:
'Warning: SimpleEmailService::sendEmail(): 6 Could not resolve host: EU_WEST_1'
This is the line of code which seems to work but connecting to the wrong endpoint
$ses = new SimpleEmailService('apikey', 'secretkey');
print_r($ses->sendEmail($m));
I have tried adding the new endpoint as the third parameter like this
$ses = new SimpleEmailService('apikey', 'secret','eu-west-1');
But that just generates the error.
Can anyone tell me the correct code to use to set the eu-west-1 endpoint to send emails through?
Thanks
I had faced the same problem with AWS PHP library for uploading files to S3. Even though I was setting up the region from us-east-1 to eu-west-1 it was still taking us-east-1 as by default. I would suggest you to look for region configurations in library and how it is overriding.
SES Email Host for us-east-1 and eu-west-1 are different. So even though if you are passing correct API and Secret, it might not work because of default region.
If this debug process doesn't work can share the screenshot of what you region you are getting before email dispatch. I would love to explore further.
I found the problem.
Looks like there was a typo within the code on github, it had these 3 lines in the file 'SimpleEmailServices.php:
const AWS_US_EAST_1 = 'email.us-east-1.amazonaws.com';
const AWS_US_WEST_2 = 'email.us-west-2.amazonaws.com';
const AWS_EU_WEST1 = 'email.eu-west-1.amazonaws.com';
He'd missed the underscore in the AWS_EU_WEST1.
I have installed zyx-phpmailer extension for send mail function in yii2 and working properly. But, when i checked via yii debugger the recipient is empty. If I using swiftmailer, there is no problem, but I must using zyx-phpmailer :(
code :
Yii::$app->mailer->compose()
->setTo('people#blabla.com')
->setFrom('admin#example.com')
->setSubject('Test')
->send();
Result (yii debugger) :
From : admin#example.com
To : empty // <- this is a problem
Subject : Test
Text body (not set)
Successfully sent : Yes
How to solve this issue? I'm still learning using yii2 framework.
Check if your current mailer is actually the new extension and not SwiftMailer, you can trace it at runtime by calling this Yii::trace(Yii::$app->get('mailer')). Maybe you did not fully configure it.
Try ->setTo(['people#blabla.com' => 'People Blabla']). The first one being the email address itself and the second one being the name.
it work;try
Yii::$app->mail->compose()
->setFrom(['xx#xx.com' => 'My Example Site'])
->setTo([$form->email => $form->name])
->setSubject($form->subject)
->setTextBody($form->text)
->send();
*,
I want to upload daily some .EML-Files to my Exchange Server 2013. So I found from Google a PHP class from James Iarmes calles PHP-EWS.
https://github.com/jamesiarmes/php-ews
I tried some examples and I think, this class is good for me. There is only one problem: no example-code in this wiki and unfortunately I do not get it out :-(
Is there someone, who works with this class and can post a example to do uploads to Exchange-Servers using PHP-EWS?
Regards
Based on the answer given by Michael up above, I can't tell you how you'd do it in jamesaires/php-ews, but I can tell you how to do it in my ews library, garethp/php-ews. I'd highly recommend you look in to my library instead, as it's maintained and PSR-4 compatible. Here's how you'd do it using Michael's method
<?php
require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\Mail\MailAPI;
$api = MailApi::withUsernameAndPassword('server', 'username', 'password');
$message = new Type\MessageType();
$message->setMimeContent(file_get_contents('./file.eml'));
//Set the message as not a draft using extended property types
$extended = new Type\ExtendedPropertyType();
$fieldUri = new Type\ExtendedFieldURI();
$fieldUri->setPropertyTag("0x0E07");
$fieldUri->setPropertyType(\jamesiarmes\PEWS\API\Enumeration\MapiPropertyTypeType::INTEGER);
$extended->setExtendedFieldURI($fieldUri);
$extended->setValue(1);
$message->addExtendedProperty($extended);
//Pass it to the Send Mail function, but to SaveOnly without actually sending the email
$itemId = $api->sendMail($message, array('MessageDisposition' => 'SaveOnly'));
$inbox = $api->getFolderByDistinguishedId('inbox');
//Move the mail message from the sent folder to whatever folder we want to send it to
$api->getClient()->MoveItem(Type::buildFromArray(array(
'ToFolderId' => array('FolderId' => $inbox->getFolderId()->toArray()),
'ItemIds' => array(
'ItemId' => $itemId->toArray()
)
)));
I've never worked with PHP-EWS but I do know that you can put a .eml into Exchange.You won't be using the UploadItem operation. You'll use the CreateItem operation. Here's the workflow:
Create an email object.
Set the MimeContent property with the contents of your .eml file.
Set the PR_MESSAGE_FLAGS_msgflag_read property.
Use the CreateItem operation, or whatever the client-side equivalent is in PHP-EWS.
I'm fairly confident that this will work as I remember writing this in the official documentation.
I have successfully done with the authentication of Evernote with PHP.
And I have got this response.
Array ( [oauth_token] => S=s1:U=6316e:E=144fcfdfdb9:C=13da54cd1ba:P=185:A=maheshchari-2599:V=2:H=6da806fe92b9289cf0334f04e2afdc55 [oauth_token_secret] => [edam_shard] => s1 [edam_userId] => 405870 [edam_expires] => 1395813907897 [edam_noteStoreUrl] => https://sandbox.evernote.com/shard/s1/notestore [edam_webApiUrlPrefix] => https://sandbox.evernote.com/shard/s1/ )
Now, I want the list of notebooks of the user which has been authenticated with evernote.
I have done a lot of research online but I couldnt find any thing which helps, I have came to know that guid is necessary to get the list of notebooks.
From where I can find that? And how can i access the notestore and userstore?
How can i call the functions of notestore and userstore to fetch the data of user's account and user's notes in php?
Thanks in Advance.
Using the Evernote SDK for PHP, you can list notebooks like the way below:
$client = new Client(array('token' => $authToken));
$noteStore = $client->getNoteStore();
$notebooks = $noteStore->listNotebooks();
All the API references can be found here.
Also, you shouldn't make your token public. Please make sure your token string you put can't be used any more. If you need more help on this, you can get supports from Evernote developer support.
https://github.com/evernote/evernote-sdk-php
go to this link and download this zip then go to sample folder then go to client folder and run EDAMTest.php page.
and add authtoken.
first off let me "warn" you that i am not a PHP developer and am pretty clueless about PHP. I'm the developer of the WCF Service in question and am trying to support the PHP developer on staff who is trying to consume this service.
He doesn't have a Stackoverflow login and is to busy beeing pissed off at WCF to type anything without profanity ;-)
Anyhow, the service is using the following security configuration:
<security mode="Message">
<message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" />
</security>
This means the message is encrypted over the line, i believe this requires a certificate which has been installed on the webserver and when consuming the service from .NET works without any problems at all.
We've looked at fiddler communication and suspect RequestSecurityTokenResponse to be of import. I'm suspecting a handshake where a securitytoken is requested by the client, this is generated with a GUID as reference, the value is used to encrypt the request and the GUID is send as a reference.
This is all speculation though, so far we have been unable to get the requests to even remotely look the same.
Any pointers in the right direction would be much appreciated.
So far we're trying this with WSE-PHP, which can be found through google.
EDIT:
We've been able to confirm our thoughts with Fiddler and working clients do seem to do a handshake, there are three requests (and responses) in total which seem to exchange only security information, they are calling the following actions:
http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue
http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue
http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT
After this last call a request is made with an action which seems to indicate a call to the actual webservice method:
http://XXXXXXXXXXXXXX/WCF/ICompany/TestConnection
This seems to have to do with SAML (i love you google) so i added this as a tag.
Yes, there is support for WS-Security in PHP. Some assembly is required. See, for example, Secured Web Services with PHP. The WS-* specifications are written and implemented for interoperability, that is, so that the will operate across different platforms, vendors, transports, and languages. It is widely adopted, and the 1.1 version has been an OASIS standard since 2006.
Perhaps it would help defuse the tenion and be instructive if your PHP developer would show the ability to consume any web service that uses WS-Security, just to take your service and WCF out of the equation for a little while.
After my long workout for Email WCF service with attachment. Now i am able to send an email from PHP using WCF service. Here is code snippet.
<?php
ini_set('display_errors',1);
require_once ('nusoap.php');
$parameters= new StdClass();
$parameters->emailinfo = new StdClass();
$fileAttachmentPath = 'example.csv';
$data = base64_encode(file_get_contents($fileAttachmentPath));
$parameters->emlinfo->NoFileInfo = true;
$parameters->emlinfo->FileNameWithExt = "example.csv";
$parameters->emlinfo->FileContentBase64 = $data;
//$parameters->emlinfo->FileAttachment = $parameters->ArrayOfFileAttachment;
//$parameters->emlinfo->FileAttachment = (array) $parameters->emlinfo->FileAttachment;
$parameters->emlinfo->MailTo='';
$parameters->emlinfo->MailFrom='';
$parameters->emlinfo->MailMessage='';
$parameters->emlinfo->MailBody='';
$parameters->emlinfo->MailSubject='';
$parameters->emlinfo->MailType='';
$parameters->emlinfo->UserId='';
$parameters->emlinfo->Password='';
$parameters->emlinfo->SmtpId='';
$parameters->emlinfo->Token='';
$parameters->emlinfo->ApplicationId='';
$parameters->emlinfo->VisitorName='';
$parameters->emlinfo->VendorId='';
$parameters->emlinfo->ReplyTo='';
try {
$braspag = new SoapClient('WSDL Sevice',
array(
'trace' => 1,
'exceptions' => 1,
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL,
'soap_version' => SOAP_1_1,
'encoding' => 'UTF-8'
)
);
//$SendEmailResponse = $braspag->__getTypes();
$SendEmailResponse = $braspag->SendEmail($parameters);
}
catch(SoapFault $fault) {
//echo 'Ocorreu um erro: ' , $fault->getMessage();
}
var_dump($parameters->emlinfo);
?>
Regards,
Rahul Soni.
Why dont you setup a platform independent UI project using something like SOAP UI where it will enable you to have automated tests against your WCF service, guaranteeing your contracts are sound while benefiting the PHP consumer. The reason this benefits the PHP consumer is that he will have automated test cases which he can profile/run/precident he can use to make his php side of things.
One thing to note is that .net namespacing can cause issues for other languages with SOAP. I really really recommend you investigate SOAP UI or a free alternative. Possibly an alternative that is free is fiddler, however I believe that is not automated.
Here are some other helpers for your PHP consumer:
http://weblogs.asp.net/gunnarpeipman/archive/2007/09/17/using-wcf-services-with-php.aspx
https://github.com/geersch/WcfServicesWithPhp5
I don't know a lot about WCF but it seems that is SOAP based. You can start by looking at php Soap functions. I see that also supports JSON communication, check JSON functions from php.
(this is a bit long to add as comment to Visual Stewart's answer)
clientCredentialType="UserName"....This means the message is encrypted over the line
Not really. The message is not encrypted, but it will be sent via SSL. From the published docs:
Username
Allows the service to require that the client be authenticated with a user name credential. Note that WCF does not allow any cryptographic operations with user names, such as generating a signature or encrypting data. WCF ensures that the transport is secured when using user name credentials.
--
Note the difference between the message and the transport.
Authentication may be derived from a client certificate used for the transport, or negotiated (NTLM).
If the server is configured with clientCredentialType="UserName" PHP consumer must use some WS-Security implementation to send Username and Password SOAP security headers to the server.
<soapenv:Envelope>
<soapenv:Header>
<wsse:Security >
<wsse:UsernameToken>
<wsse:Username>bob</ wsse:Username>
<wsse:Password Type="PasswordText">bob1</ wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body> ... </soapenvBody>
</soapenv:Envelope>
Keep in mind that the server can be configure to acept plain or hashed password. So the client must send plain or hashed password.