Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

ps. - I have placed (tried placing) in the 'body' of the service - which is using 'post' - the HTML parameter (in lower case 'html') - and the api on the other side complains that I'm not sending over an email 'body' in response ---- I guess the question is - how do I place the 'html' parameter - in the body - so that the sendgrid api on the other side - recognizes it as a parameter - and picks up the HTML that's in the body - as the body of the email.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

As an update here - I had to change the app slightly for a demo for my client tomorrow - and the 'tests' of email UI's are not part of the deliverable.

Here is how to launch the portion of the app - that - when clicked - will test the HTML functionality...

click here....
Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Sending 2 page HTML email with SendGrid

Hi Bruce,

I'm back with the solution.

  1. Create new REST service with following settings:

    1.1. Settings:
    http://prntscr.com/5m2r5s/direct

    1.2. Request:
    http://prntscr.com/5m2rix/direct
    http://prntscr.com/5m2rry/direct

    1.3. Use following code when you need to send Email:

    pre

    //Here you can specify needed fileContent.
    var fileContent = 'Hi';

    //where "testFileName.txt" is your attach file name.
    var fileName = 'ZZZ.txt';

    var blob = new Blob([fileContent], { type: "text/xml"});

    var formData = new FormData();
    formData.append("files[" + fileName + "]", blob);

    var body = {
    "subject": "subject 1",
    "text": "text 1",
    "from": "test@appery.io",
    "api_user": "apiuser",
    "api_key": "apikey",
    "to": "test@gmail.com"
    };

    for(var i in body)
    formData.append(i, body);

    sendWithProxy.execute({

    'body': {data: formData},

    });

    /pre

    Note: this example contains how to send attaches also. You can remove this part.

    Regards.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

Yurii , awesome !!! I'll give it a go now ... My client will be overjoyed!! ( me too !!) thanks and welcome back !!!

Best, Bruce

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Sending 2 page HTML email with SendGrid

Bruce,

Also here is screen shot for proxy settings: http://devcenter.appery.io/documentat...

Regards.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

Yurii,

In terms of the link you just sent - it takes me to the Appery Team settings --- likely not what you intented??

Very interested in the correct settings for my proxy - please let me know...

Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

ok - got the correct one ---- thanks!!!.

So - quick question - and I believe I know the answer - but just to ensure - in your sample code above - I would replace the "text": "text 1" -- with 'html' --- and then my html - correct?

I also assume that your sendWithProxy.execute({
'body': {data: formData} ... is an instance of the sendmail service that I created above - where I have no mappings (as the mapping is done in the javascript that calls the execution above) - and only pre & post javascript type stuff that does logging before-after & captures and reports on any errors.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Sending 2 page HTML email with SendGrid

Bruce,

Yes, "sendWithProxy" - is service(that i described in a solution) datasource on the page.

Regards.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Sending 2 page HTML email with SendGrid

I implemented what was above (mostly without exception....) but :-) - nothing sends and I'm not sure how to trap the error from the service (if there is one ...) Here's my code

function fsharebyemail(){
// share opportunities by email... the new routine
var formData = new FormData();
var api_user = 'mapiusercodeishere';
var api_key = 'mypasswordishere';
var ssubject = '';
var shtml = fscrubhtml(Appery('html_tosend').text());
console.log('raw html is:' + shtml ); // this results in the formatted html - and looks mostly correct - good enough for debugging and testing
ssubject = localStorage.getItem('susername') + ' has shared a Sales Opportunity for: ' + Appery('label_opptyname').text() + ' with you' ;
console.log( 'subject is: ' + ssubject ); // this also looks good in the log
var body = {
"subject": ssubject ,
"html": shtml,
"from": "a href="mailto:bruce.stuart@the-software-studio.com" rel="nofollow"bruce.stuart@the-software-studio.com/a",
"api_user": api_user,
"api_key": api_key,
'fromname': 'TrueBlue COA Adminstrator',
"to": localStorage.getItem('s_emailtoshare')
};
for(var i in body)
formData.append(i, body);
service_send_email_byproxy.execute({
'body': {data: formData},
});
}

// what comes back from the execution - is a 404 not found.... with this result:

(console log:)
Image

and this as the 'more information' on the 404 error:

Image

What might I need to tweak to get this to work like it did for you ?

Best,

Bruce

Return to “Issues”