I would like to add email adress of my clients to billing and shipping address.
To do that, I have tried to add var order.getCustomerEmail(), var email into html address template. But it doesn't fill it in.
Code example:
{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
{{var country}}<br/>
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}<br/>F: {{var fax}}{{/depend}}
**<br/>Email: {{var order.getCustomerEmail()}}**
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}
Can it be because of not registered users? But they are also required to enter an email address.
If you want the customer's email in sales order email, change the below file
\app\code\core\Mage\Sales\Model\Order.php
locate the function sendNewOrderEmail()
$email =$order->getCustomerEmail();
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml,
'email' => $email
)
);
Now you can access this variable like
{{var email}}
NOTE I will advice not to make changes in the core file
Related
I'm trying to trigger an email from Google App script.
const body = HtmlService.createHtmlOutput( "A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh"){
MailApp.sendEmail("abc#abc.com",task,body,{name:"ABC"})
}
The problem is, email body give nothing but just this
screen shot
What is the mistake?
In your script, HtmlOutput object is directly used as the text body. I think that this is the reason for your issue. And, the 3rd argument of sendMail is the text body. In your situation, I thought that HTML body might be your expcted result. In this case, how about the following modification?
Modified script:
const body = HtmlService.createHtmlOutput("A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh") {
MailApp.sendEmail("abc#abc.com", task, null, { name: "ABC",htmlBody: body.getContent() });
}
Or, in your script, I think that you can directly use the HTML as follows.
if (props.val == "Jonh") {
MailApp.sendEmail("abc#abc.com", task, null, { name: "ABC",htmlBody: "A <b> new task </b> have been added to the Task Manager <br> www.abc.com" });
}
Or,
const body = HtmlService.createHtmlOutput("A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh") {
MailApp.sendEmail({
to: "abc#abc.com",
subject: task,
htmlBody: body.getContent(),
name: "ABC"
});
}
Or,
if (props.val == "Jonh") {
MailApp.sendEmail({
to: "abc#abc.com",
subject: task,
htmlBody: "A <b> new task </b> have been added to the Task Manager <br> www.abc.com",
name: "ABC"
});
}
References:
createHtmlOutput(html)
sendEmail(recipient, subject, body, options)
sendEmail(message)
I'm putting together a contact form using Svelte and SendGrid. Here is a basic app.svelte:
<script>
import sgMail from '#sendgrid/mail';
sgMail.setApiKey(import.meta.env.VITE_SENDGRID);
function submitForm() {
const msg = {
to: 'test#example.com',
from: 'test#example.com',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>'
};
console.log('Form submitted');
sgMail.send(msg);
}
</script>
<form on:submit|preventDefault={submitForm}>
<button type="submit">Submit</button>
</form>
The code above does not send an email after the user selects submit on the form, despite the function being called (it logs Form submitted in the console). When I move all code from submitForm() outside the function, the code executes on page load, so I know it's not an issue with my API key.
Any suggestions what I am missing?
Svelte is a frontend environment only. The Sendgrid package is desinged for a server side / node.js environment. In your example, your Sendgrid API key would be exposed because you're trying to use it on the frontend / client side.
A solution may be to look at SvelteKit, which has the concept of 'endpoints' which always run on the server side. Or you can create an express server to handle the sending of email to Sendgrid.
EDIT: The solution is to use Sveltekit endpoints. Endpoints always run on the server. Your final solution may look something like this:
File: /src/routes/api/sendmail.ts or /src/api/sendmail.js
import sgMail from "#sendgrid/mail";
sgMail.setApiKey(import.meta.env.VITE_SENDGRID);
export async function get(page) {
const msg = {
to: "test#example.com",
from: "test#example.com",
subject: "Sending with SendGrid is Fun",
text: "and easy to do anywhere, even with Node.js",
html: "<strong>and easy to do anywhere, even with Node.js</strong>",
};
console.log("Form submitted");
const output = await sgMail.send(msg);
return {
body: output,
};
}
File /src/routes/index.svelte
<script>
function submitForm() {
fetch("/api/sendmail");
}
</script>
<form on:submit|preventDefault={submitForm}>
<button type="submit">Submit</button>
</form>
I am using protractor with angular 6. stuck in a situation where i want to write test case to test a list of table headers which are created with data coming from backend called in ngOnInit.
i tried using tick and fakeAsync but keep on getting error
Failed: Cannot read property 'assertPresent' of null
below is my code:
app.po.ts
goToScannersList() {
return browser.get('/scanners');
}
getScannersList() {
let items = element.all(by.css('.scannerlist th')).map(function (elm) {
return elm.getText();
});
return items;
}
If i use spec like in 1) i get error mentioned above even if i remove page.goToScannersList();
but if use spec like in 2) my test is success irrespective of what value it returns.
1)
app.e2e-spec.ts
it('should display list of scanners', fakeAsync(() => {
page.goToScannersList();
tick(4000);
expect(page.getScannersList()).toEqual([
"ScannerID",
"Desc",
"Owner"
]);
}));
2)
app.e2e-spec.ts
it('should display list of scanners', () => {
page.goToScannersList();
fakeAsync(()=>{
tick(4000);
expect(page.getScannersList()).toEqual([
"ScannerID",
"Desc",
"Owner"
]);
})
});
scanners.component.html
<table class="scannerlist" id="scannersList" style="text-align:center;width:100%">
<thead>
<tr ><th *ngFor="let col of scannerKeys">{{col}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of scannerData">
<td>{{row.ScannerID}}</td>
<td>{{row.Desc}}</td>
<td>{{row.Owner}}</td>
</tr>
</tbody>
</table>
scanners.component.ts
ngOnInit() {
this.scannerService.getScannerDetails().subscribe((data)=>{
this.scannerData = data.Data;
this.scannerKeys = this.getKeys(data.Data[0]);
});
}
let me know if anybody has any idea how to implement it. thanks in anticipation.
So I do want to say that I've been searching for the answer for this and I've also tried to console.log my req.body post form and I keep getting undefined. So I feel that I'm losing the data from the form I send, I'm not sure what I"m doing wrong. So time to show some code.
As a note: I am using Handlebars for my Express Setup.
app.js
var express = require('express'),
exphbr = require('express3-handlebars'), // "express3-handlebars"
nodemailer = require('nodemailer'),
helpers = require('./lib/helpers'),
app = express(), handlebars;
// Create `ExpressHandlebars` instance with a default layout.
handlebars = exphbr.create({
defaultLayout: 'main',
helpers : helpers,
extname : '.html',
// Uses multiple partials dirs, templates in "shared/templates/" are shared
// with the client-side of the app (see below).
partialsDir: [
'views/shared/',
'views/partials/'
]
});
// Register `hbs` as our view engine using its bound `engine()` function.
app.engine('html', handlebars.engine);
app.set('view engine', 'html');
require("./routes")(app, express, nodemailer);
app.listen(3000);
routes.js
module.exports = function (app, express, nodemailer) {
// set up the routes themselves
app.get('/', function (req, res) {
res.render('home', {
title: 'Larry King Orchestra'
});
});
// I cut out a majority of my routes to make this easier to read.
// SEND EMAIL FROM FORM
app.post('/', function (req, res) {
console.log("WTF");
console.log(req.body.name);
console.log(req.body.email);
var mailOpts, smtpTrans;
//Setup nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
smtpTrans = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: "email#gmail.com",
pass: "password"
}
});
//Mail options
mailOpts = {
from: req.body.email, //grab form data from the request body object
to: 'anotheremail#gmail.com',
subject: 'LKO Contact Form',
html: 'From: ' + req.body.name + ' <' + req.body.email + '> <br>Phone: ' + req.body.tel + '<br>Date of Event: ' + req.body.date + '<br>Location: ' + req.body.location + '<br>Details & Comments:<br>' + req.body.message + '<br><br><p>Email form provided by WavaMedia.'
};
smtpTrans.sendMail(mailOpts, function (error, response) {
//Email not sent
if (error) {
res.render('home', {
title: 'Larry King Orchestra',
msg: 'Error occured, message not sent.',
err: true,
page: 'home'
});
}
//Yay!! Email sent
else {
res.render('home', {
title: 'Larry King Orchestra',
msg: 'Message sent! Thank you.',
err: false,
page: 'home'
});
}
});
});
// STATIC ROUTE FOR ASSESTS
app.use(express.static('assests/'));
};
I renamed the handlebars extension to be .html and I have the main layout using partials. SO app.get('/') will show this next file as a partial, and render it on the page.
contact.html
<form class="contact" action="/" method="post">
<label for="name">Name</label>
<input type="name" name="name" id="name">
<label for="email">Your Email (required)</label>
<input type="email" name="email" id="email">
<label for="tel">Phone Number</label>
<input type="tel" name="tel" id="tel">
<label for="date">Date of Your Event</label>
<input type="date" name="date" id="date">
<label for="location">Venue/Location</label>
<input type="location" name="location" id="location">
<label for-"message">Details & Comments</label>
<textarea name="message" id="message" rows="3"></textarea>
<input type="submit" name="submit" id="submit" value="Send" class="btn btn-default">
</form>
My Error:
TypeError: Cannot read property 'name' of undefined at c:\xampp\htdocs\lko\routes.js:129:26 at callbacks (c:\xampp\htdocs\lko\node_modules\express\lib\router\index.js:164:37) at param (c:\xampp\htdocs\lko\node_modules\express\lib\router\index.js:138:11) at pass (c:\xampp\htdocs\lko\node_modules\express\lib\router\index.js:145:5) at Router._dispatch (c:\xampp\htdocs\lko\node_modules\express\lib\router\index.js:173:5) at Object.router (c:\xampp\htdocs\lko\node_modules\express\lib\router\index.js:33:10) at next (c:\xampp\htdocs\lko\node_modules\express\node_modules\connect\lib\proto.js:193:15) at Object.expressInit [as handle] (c:\xampp\htdocs\lko\node_modules\express\lib\middleware.js:30:5) at next (c:\xampp\htdocs\lko\node_modules\express\node_modules\connect\lib\proto.js:193:15) at Object.query [as handle] (c:\xampp\htdocs\lko\node_modules\express\node_modules\connect\lib\middleware\query.js:45:5)
So I'm not sure where I'm going wrong with the code. I believe the form is sending data to my node app, but where it's going, I'm not sure. I've setup the post method and so far no luck :( I have been trying for a couple days now. I have nodemailer installed as well. I've restarted the server, updated node and npm.
JavaScript Node Guru Masters, only you can show me the light! And thanks for reading though all of this, totally awesome!
app.use(express.bodyParser());
add that to your app.js
that's what grabs information from the post data form.
You have to require body parser package for this.
At first you have to install it with npm.
$ npm install --save body-parser
Then require that in your js file.
var bodyParser = require('body-parser');
Then add the parser. As you are using html post method it uses urlencoded as encoding type. For that add this line.
var urlencodedParser = bodyParser.urlencoded({ extended: false });
(If you use json you must use bodyParser.json() instead of this)
Now add the parser with the encoding type to app.post method as follows.
app.post('/',urlencodedParser, function (req, res) {
//your code here
});
You don't have to be explicitly mention any bodyParser or bodyParer.json
Instead You can make it simple to use this because this is a built-in middleware function in Express.
app.use(express.json());
app.use(bodyparser.urlencoded({extended : true }));
I see it all over the place, yet, I could not find one example about this (maybe I don't know the proper wording), I am trying to build using ASP .Net MVC2 (but any example on just ASP .Net would be also helpful) a process that will send a link to the user at the end of the registration process to let him confirm his registration. Also, a similar process to let the user to reset his password, with the typical "forgot password" and send a link/url so that the user can click and type a new password. Can someone help me to either find an example or at least to let me know how to "google" it?
Thanks,
Mark
For the forgot password, you can make a view like this
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true)%>
<p><%: ViewData["Error"] %></p>
<p> Have you forgotten you password? No problem!</p>
<div class="editor-label">
<%: Html.Label("Fill in your username") %>
</div>
<div class="editor-field">
<%: Html.TextBox("userName") %>
</div>
<p> and <input type="submit" value="click here" /> to reset your password.</p>
<% } %>
and as a controller (first make an model from the aspnetdb (if you don't see it press the 'show all files' button))
This must be placed right after the controller definition
aspnetdbEntities aspnetdb = new aspnetdbEntities();
Then follows this
public ActionResult ForgottenPassword()
{
return View();
}
[HttpPost]
public ActionResult ForgottenPassword(FormCollection formValue)
{
var userName = formValue["userName"];
try
{
var useraccount = aspnetdb.aspnet_Users.Single(c => c.UserName == userName);
var fromAddress = "put an email-address";
var message = new MailMessage(fromAddress, user.Email)
{
Subject = "",
Body = "a link to a controller that lets the user put in a
new password and then save that password to the aspnetdb."
(that controller will most likley require a username)
"or a link with a new random password in it tht you have put
as his password like this:"
useraccount.aspnet_Membership.Password = "random password";
aspnetdb.SaveChanges;
};
var client = new SmtpClient("smtpServerName");
client.Send(message);
return View();
}
catch
{
ViewData["Error"] = "Please give up an existing username";
return View();
}
}
I hope this answer was helpfull.