· 11 years ago · Aug 24, 2015, 03:28 PM
1sendEmail(form) {
2
3var data = {
4 contactName: form.name,
5 contactEmail: form.email,
6 comments: form.comments || null
7};
8
9var req = {
10 method: 'POST',
11 // url: 'http://localhost:9030/email', <- my express port
12 url: location.origin + '/email',
13 // url: 'https://myherokuapp.herokuapp.com/email', <- my heroku app
14 headers: {
15 'Content-Type': 'application/json'
16 },
17 data: data
18};
19
20this.$http(req)
21.then((result) => {
22 console.log('success is...', result);
23 return result;
24})
25.catch((error) => {
26 console.log('error is...', error);
27 return error;
28});
29
30var transport = nodemailer.createTransport("SMTP", {
31 service: 'Mandrill', // use well known service.
32 // If you are using @gmail.com address, then you don't
33 // even have to define the service name
34 auth: {
35 user: "xxxxx@gmail.com",
36 pass: "xxxxxxxxxxxxxxxx"
37 }
38});
39
40console.log('SMTP Configured');
41
42var message = {
43
44 // sender info
45 from: 'Sender: <' + req.body.contactEmail + '>',
46
47 // Comma separated list of recipients
48 to: '"Info:" <info@example.com>',
49
50 // Subject of the message
51 subject: 'Nodemailer is unicode friendly ✔', //
52
53 headers: {
54 'X-Laziness-level': 1000
55 },
56
57 // plaintext body
58 text: "Interestn" +
59 "===========n" +
60 "n" +
61 "**How** are you?"
62};
63
64console.log('Sending Mail');
65transport.sendMail(message, function(error) {
66 if (error) {
67 console.log('Error occured');
68 console.log(error.message);
69 return;
70 }
71 console.log('Message sent successfully!');
72
73 // if you don't want to use this transport object anymore, uncomment following line
74 transport.close(); // close the connection pool
75});
76
772015-08-24T15:12:58.800676+00:00 app[web.1]: POST /email - - ms - -
782015-08-24T15:13:15.858302+00:00 app[web.1]: { contactName: 'testing',
792015-08-24T15:13:15.858307+00:00 app[web.1]: contactEmail: 'asdf@adsf.com',
802015-08-24T15:13:15.858309+00:00 app[web.1]: comments: 'asdfasdf' }
812015-08-24T15:13:15.858316+00:00 app[web.1]: Email params (name):testing
822015-08-24T15:13:15.858376+00:00 app[web.1]: Email params (email):asdf@adsf.com
832015-08-24T15:13:15.858417+00:00 app[web.1]: Email params (comments):asdfasdf
842015-08-24T15:13:15.858498+00:00 app[web.1]: SMTP Configured
852015-08-24T15:13:15.858537+00:00 app[web.1]: Sending Mail
862015-08-24T15:13:15.889774+00:00 app[web.1]: Message sent successfully!
872015-08-24T15:13:45.845230+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/email" host=secret-river-5414.herokuapp.com request_id=5c1e8378-6971-4253-86e2-a9647fc7e0d4 fwd="14.200.153.28" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
882015-08-24T15:13:45.857582+00:00 app[web.1]: POST /email - - ms - -