2013-05-26 4 views

Odpowiedz

6

Można ustawić od parametru w kilka sposobów:

var SendGrid = require('sendgrid').SendGrid; 
var sendgrid = new SendGrid(user, key); 
sendgrid.send({ 
    to: '[email protected]', 
    from: '[email protected]', // Note that we set the `from` parameter here 
    fromname: 'Name', // We set the `fromname` parameter here 
    subject: 'Hello World', 
    text: 'My first email through SendGrid' 
}, function(success, message) { 
    if (!success) { 
    console.log(message); 
    } 
}); 

lub można utworzyć obiekt Email i wypełnić rzeczy na tym, że:

var Email = require('sendgrid').Email; 
var email = new Email({ 
    to: '[email protected]', 
    from: '[email protected]', 
    fromname: 'Name', 
    subject: 'What was Wenger thinking sending Walcott on that early?', 
    text: 'Did you see that ludicrous display last night?' 
}); 

sendgrid.send(email, function() { 
    // ... 
}); 

może chcesz wziąć kilka minut i przejrzyj the README document on the Github page. Ma dość szczegółowe informacje na temat korzystania z biblioteki i różnych funkcji, jakie oferuje.

+0

Dzięki. Czytałem ten README iz jakiegoś powodu nie widziałem pola 'fromname' w dokumentach, próbując znaleźć coś na ten temat. Następnym razem wypróbuję Ctrl + F :) –

+0

co to jest użytkownik i klucz. Myślę, że kluczem jest klucz API, ale co to jest użytkownik? to jest nazwa użytkownika lub jakikolwiek inny –

+0

To już nie działa. Zobacz odpowiedź @ na niszczarkę poniżej. – Pier

3

Jeśli używasz pomocnika biblioteki nodejs, należy wykonać następujące argumenty:

from_email = new helper.Email("[email protected]", "Email Name"); 
2

Aktualizacja przykład ze składni w najnowszej wersji Sendgrid Node.js library.

sendgrid.send({ 
    to: '[email protected]', 
    from: { 
     email: '[email protected]', 
     name: 'Sender Name' 
    }, 
    subject: 'Hello World', 
    text: 'My first email through SendGrid' 
}); 
+0

Dzięki za ten sam problem i nie mogłem znaleźć pola "name" w dokumentacji, w rzeczywistości dokumenty nie są szczególnie łatwe w nawigacji. – JMac

+1

Zgadzam się. Wydałem [żądanie pobrania] (https://github.com/sendgrid/sendgrid-nodejs/pull/645) próbując wyjaśnić to nieco w dokumentacji, ale bezskutecznie. – Incinerator