How to add new email template and call/ use that template in prestashop 1.6 - email

I created a module in which I am displaying all the dormant users by combining two tables - customer and order table and now I Want to perform bulk action (mail send action ) to the dormant users , But I want to make a email template in which this template can be edited and used for sending email to the dormant users from the BO.
How to send email using a template in prestashop ? .
I created a email template (created.html and .text file ) in email folder, Also edited classes/Langugae.php
// Added natives mails files
$mFiles = array(
'account.html', 'account.txt',
'backoffice_order.html', 'backoffice_order.txt',
'bankwire.html', 'bankwire.txt',
'cheque.html', 'cheque.txt',
'contact.html', 'contact.txt',
'contact_form.html', 'contact_form.txt',
'credit_slip.html', 'credit_slip.txt',
'download_product.html', 'download_product.txt',
'employee_password.html', 'employee_password.txt',
'forward_msg.html', 'forward_msg.txt',
'guest_to_customer.html', 'guest_to_customer.txt',
'in_transit.html', 'in_transit.txt',
'log_alert.html', 'log_alert.txt',
'newsletter.html', 'newsletter.txt',
'order_canceled.html', 'order_canceled.txt',
'order_conf.html', 'order_conf.txt',
'order_customer_comment.html', 'order_customer_comment.txt',
'order_merchant_comment.html', 'order_merchant_comment.txt',
'order_return_state.html', 'order_return_state.txt',
'outofstock.html', 'outofstock.txt',
'password.html', 'password.txt',
'password_query.html', 'password_query.txt',
'payment.html', 'payment.txt',
'payment_error.html', 'payment_error.txt',
'preparation.html', 'preparation.txt',
'refund.html', 'refund.txt',
'reply_msg.html', 'reply_msg.txt',
'shipped.html', 'shipped.txt',
'test.html', 'test.txt',
'voucher.html', 'voucher.txt',
'voucher_new.html', 'voucher_new.txt',
'order_changed.html', 'order_changed.txt',
'dormant_email.html', 'dormant_email.txt'
);
I added my email template - 'dormant_email.html', 'dormant_email.txt' in mails\en folder

ok I solved this by adding the template file by creating mail.en folder in module folder ( modulename/emails/en/)
and by below code
if (!Mail::Send(
$this->context->language->id,
'dormant_email',
Mail::l('Hello Long Time No See ! Please Visit and Get a Chance to Win'),
$templateVars,
$dormantUserEmailID,
null, null, null, null, null, dirname(__FILE__).'/mails/', true, $this->context->shop->id))
die('0') ;echo "<script type=\"text/javascript\">alert('Email Send');</script>"; return true;
die('1');echo "<script type=\"text/javascript\">alert('Email not Send');</script>"; return false;
I am able to send email and use the template and it is been listing when I click on the
Localization->transalations -->modify transalations
select email template translations and select English and click modify button and in the modules when u expand your module the email template can be seen and can be edited by edit tool .

Related

Jenkins emailext not sending mails

I am currently trying to understand why Jenkins is not sending emails.
The expected behavior is, that Jenkins will send emails to the whole team if the master branch is broken. If a feature branch breaks a email to the person who broke it, should be send.
Emails for the master branch are working, but not for broken feature branches.We are using the email-ext plugin. If you take a look at the code below you will see that the getEMailRecipients function will return an empty string for feature branches.
Docs example
In the docs an example is given that should
Send an email to abc plus any addresses returned by the providers
emailext (
body: 'A Test EMail',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
subject: 'Test',
to: 'abc'
)
My understanding of this example is, that an email should be send even if the to property is empty.
Property value docs
The docs for the plugin state the following for the 'CulpritsRecipientProvider' option
Sends email to the list of users who committed a change since the last
non-broken build till now. This list at least always include people
who made changes in this build, but if the previous build was a
failure it also includes the culprit list from there.
My Code
Helper functions:
def getTeamRecipients() {
return 'name1 name2 nameX'
}
def getEMailRecipients(currentBranch) {
return (currentBranch.toLowerCase().contains("current") ||
currentBranch.toLowerCase().contains("master")) ?
getTeamRecipients() :
""
}
def sendEMail(recipients) {
emailext (
to: recipients,
subject: "Job '${env.JOB_NAME}' is in state ${currentBuild.currentResult}",
body: "See ${env.BUILD_URL} for more details",
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
]
)
}
Email Send part:
if (currentBuild.currentResult == "FAILURE") {
def recipients = getEMailRecipients("$BRANCH_NAME")
sendEMail(recipients)
}
Does anyone have an idea what is wrong with my build script code?

Sending emails from Hyperion server

I am trying to send emails from hyperion servers when the number of records is 0.I am writing the script code in onPostProcess().
var dtm_current = new Date();
Application.ExecuteBScript("Set BrioQuery, Mail, 'Internet Mail', mailserverwithoutquotes,fromid'"); //note that mailserver name is given without quotes and
//from id does nt have starting quote
Application.ExecuteBScript("Export Section Root.'Results', OfficeMHTML, 'job_output', Silent, email, 'Testing Email action', 'This is a test of the email action. \n\n\n', UTF-8, To, tomailid'");
Console.Writeln ( "Post Process Script complete:"+dtm_current );
I am getting the error
Emailing section 'Results' as 'Microsoft Office Web Archive' to:
com'
Export failed. Error: Connection failed to locate host, 127.0.0.1. Is the SMTP server on port 25? (Errcode=146)
Question I have : Why it is trying to connect to localhost instead of specified email server
I have got this working.
var dtm_current = new Date();
Application.ExecuteBScript("Set BrioQuery, Mail, 'Internet Mail', emailserverwithoutquotes,'fromemailid'");
var count =1* ActiveDocument.Sections['R-Results'].RowCount;
Console.Writeln(count);
if(count > 0){
Application.ExecuteBScript("Export Section Root.'R-Results', csv, 'job_output', Silent, email, 'Testing Email action if', 'This is a test of the email action if. \n\n\n', UTF-8, To, 'tomailid'");
}
else{
Application.ExecuteBScript("Export Section Root.'R-Results', csv, 'job_output', Silent, email, 'Testing Email action else', 'This is a test of the email action else. \n\n\n', UTF-8, To, 'tomailid'");
}

Magento: Email template crashes new template form

I have a module that I'm trying to use with an email template I created. I created the .phtml template directly (not through the new template form on the backend) into the locale > en_US > template > email folder. The template seems to work as the variables passed to it work and the email gets sent fine. My only problem is that now when I go into the management > Transactional Emails > New Template, the page crashes. The dropdown is empty and everything after it does't get rendered.
I think it might have something to do with the way I'm loading the template in the modules config.xml. When I remove the reference to the template the problem goes away. Put the reference back in and the form crashes..
Config.xml
<?xml version="1.0"?>
<config>
<modules>
<Optimise_Requestcallback>
<version>0.1.9</version>
</Optimise_Requestcallback>
</modules>
<frontend>
<routers>
<requestcallback>
<use>standard</use>
<args>
<module>Optimise_Requestcallback</module>
<frontName>request-callback</frontName>
</args>
</requestcallback>
</routers>
<layout>
<updates>
<requestcallback>
<file>optimise.xml</file>
</requestcallback>
</updates>
</layout>
</frontend>
<global>
<template>
<email>
<requestcallback_template translate="label" module="requestcallback">
<label>Optimise RequestCallback</label>
<file>requestcallback_template.html</file>
<type>html</type>
</requestcallback_template>
</email>
</template>
</global>
</config>
Here is how I send the email:
public function sendemailAction() {
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('requestcallback_template');
$emailTemplateVariables = array();
//Fetch submited params
$params = $this->getRequest()->getParams();
$subjectOfMail = "Request a Callback from the Puji Website<br /><br />Product = " . $params['product'] . "<br />Name = " . $params['name'] . "<br />Email = " . $params['email'] . "<br />Telephone = " . $params['telephone'] . "<br />Message = " . $params['comment'];
$emailTemplateVariables['body'] = $subjectOfMail;
$emailTemplate->setSenderName($params['name']);
$emailTemplate->setSenderEmail($params['email']);
try {
$emailTemplate->send('billy#optimiseweb.co.uk', 'Sales', $emailTemplateVariables);
Mage::getSingleton('core/session')->addSuccess('Thank you! We will contact you very soon.');
} catch (Exception $ex) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
$this->_redirect('*/*/');
return;
}
//Redirect back to index action of (this) activecodeline-simplecontact controller
$this->_redirect('request-callback/');
}
And the template itself probably couldn't be any simpler!
<!--#subject Request a Callback from the Puji Website #-->
{{var body}}
Can anyone see an issue here that would cause the New template form to crash?
There can be various reasons, but first check config.xml file for each custom module, one-by-one.
There must be one module, where you will find code like:
module="[some-module-name-here]"
Try removing this code one-by-one and reload the transactional e-mail template form again.
I am sure, it will solve the problem.

Zend_Mail will not send bcc to sender address

I have a problem, when I want to send mail to a customer and also to the admins.
The problem is, that the customer receives the mail, but the bcc will not if the from = bcc. Is there any setting I have missed?
Could this be a server issue, or a Zend related one?
Example code I use:
$mail = new Zend_Mail();
$mail->setFrom( 'admin#example.com', 'Admin' )
->addTo( 'customer#anydomain.com', 'Customer' )
->setBodyText( 'Example' )
->addBcc('admin#example.com');
$mail->send();
The headers are (from $mail->getHeaders()):
array(3) {
["From"]=>
array(2) {
[0]=>
string(26) "Admin <admin#example.com>"
["append"]=>
bool(true)
}
["To"]=>
array(2) {
[0]=>
string(25) "Customer <customer#anydomain.com>"
["append"]=>
bool(true)
}
["Bcc"]=>
array(2) {
[0]=>
string(18) "admin#example.com"
["append"]=>
bool(true)
}
}
I stumbled on this post while working on using Zend_Mail to send a bcc to the sender address and found that for me the following does in fact work:
$fromName = 'admin';
$fromMail = 'sender#mail.com';
$mail = new Zend_Mail();
$mail->setFrom($fromEmail, $fromName);
$mail->addBcc($fromMail);
Even though the bug report http://framework.zend.com/issues/browse/ZF-8723 as linked in RakeshS's post is still marked as unresolved. My Zend version is:
const VERSION = '1.11.12';
It would be interesting to learn whether the problem would also be solved for the original posters for the updated Zend framework, if they may happen to read this
I'm getting the same behavior as you. The sender is not getting the message if the address is added as Bcc. So, it's likely to be a Zend Mail related issue (I don't think we have the same server configuration).
There is a bug added to ZF which almost similar to this issue: http://framework.zend.com/issues/browse/ZF-8723
BTW, you could also get BCC to work with the help of Zend Mail Add Header method. Please try the following work-around:
$mail->addHeader('Bcc', 'admin#example.com');
if you use only Bcc recipients without TO
read this
http://framework.zend.com/issues/browse/ZF-3509

Sending template emails in Magento

I'm creating a Magento Module that can be used to send emails in certain occasions of my website. I'm following the tutorial from Branko Ajzele and everything seems to work fine until I try to send the email where I get a false response from the Send function.
Below is the code I'm using along with the result returned:
public function sendAction() {
/*
* Loads the html file named 'custom_email_template1.html' from
* app/locale/en_US/template/email/activecodeline_custom_email1.html
*/
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('custom_email_template1');
// var_dump(Mage::getModel('core/email_template'));
//Create an array of variables to assign to template
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'Branko';
$emailTemplateVariables['myvar2'] = 'Ajzele';
$emailTemplateVariables['myvar3'] = 'ActiveCodeline';
/**
* The best part <img src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
* Opens the activecodeline_custom_email1.html, throws in the variable array
* and returns the 'parsed' content that you can use as body of email
*/
/*
* Or you can send the email directly,
* note getProcessedTemplate is called inside send()
*/
$emailTemplate->setSenderName('my name');
$emailTemplate->setSenderEmail('example#domain.com');
$emailTemplate->setTemplateSubject('STATUS CHANGED');
var_dump($emailTemplate->send('example#domain.com'));
echo "<br>";
var_dump($emailTemplate);
exit("test");
}
The var_dump given by var_dump($emailTemplate); returns the object with all the information correctly as shown below:
bool(false)
object(Gp_Notify_Model_Email_Template)#82 (19) { ["_templateFilter:protected"]=> NULL ["_preprocessFlag:protected"]=> bool(false) ["_mail:protected"]=> NULL ["_designConfig:protected"]=> NULL ["_emulatedDesignConfig:protected"]=> bool(false) ["_initialEnvironmentInfo:protected"]=> NULL ["_eventPrefix:protected"]=> string(13) "core_abstract" ["_eventObject:protected"]=> string(6) "object" ["_resourceName:protected"]=> string(19) "core/email_template" ["_resource:protected"]=> NULL ["_resourceCollectionName:protected"]=> string(30) "core/email_template_collection" ["_cacheTag:protected"]=> bool(false) ["_dataSaveAllowed:protected"]=> bool(true) ["_isObjectNew:protected"]=> NULL ["_data:protected"]=> array(6) { ["template_type"]=> int(2) ["template_subject"]=> string(14) "STATUS CHANGED" ["template_text"]=> string(208) "
ActiveCodeline custom email example by Branko Ajzele
Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.
" ["template_id"]=> string(22) "custom_email_template1" ["sender_name"]=> string(7) "my name" ["sender_email"]=> string(15) "phil#gproxy.com" } ["_hasDataChanges:protected"]=> bool(true) ["_origData:protected"]=> NULL ["_idFieldName:protected"]=> NULL ["_isDeleted:protected"]=> bool(false) } test
The thing is that although everything seems to go well the send function returns false and of course I never get to receive the email.
Is there something I'm forgetting to do like any configuration in the backend or something?
---- UPDATE ----
After some investigation I realized that there are no emails reaching their destination at all in my Magento installation which I thought they were, so figured I should start from there.
I have already added all the emails in the backend.
I checked the Locale (language) and changed it to english/US (which I read could be an issue).
Any advise?
Are u trying it on the localhost or the live site. If you are trying in the localhost then you need to correct in the php.ini file for the email setting.