public function testSendResponse() { $sendgrid = new SendGrid("foo", "bar"); $message = new SendGrid\Mail(); $message->setFrom('*****@*****.**')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**'); $response = $sendgrid->web->send($message); $this->assertEquals("{\"message\": \"error\", \"errors\": [\"Bad username / password\"]}", $response); }
public function testFromAccessors() { $message = new SendGrid\Mail(); $message->setFrom("*****@*****.**"); $message->setFromName("John Doe"); $this->assertEquals("*****@*****.**", $message->getFrom()); $this->assertEquals(array("*****@*****.**" => "John Doe"), $message->getFrom(true)); }
public function testEmailTextBodyAttachments() { $_mapToSwift = new ReflectionMethod('SendGrid\\Smtp', '_mapToSwift'); $_mapToSwift->setAccessible(true); $sendgrid = new SendGrid("foo", "bar"); $message = new SendGrid\Mail(); $message->setFrom('*****@*****.**')->setFromName('John Doe')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**'); $swift_message = $_mapToSwift->invoke($sendgrid->smtp, $message); $this->assertEquals(count($swift_message->getChildren()), 0); }
public function testConstruction() { $sendgrid = new SendGrid("foo", "bar"); $smtp = $sendgrid->smtp; $this->assertEquals(new SendGrid\Smtp("foo", "bar"), $smtp); $message = new SendGrid\Mail(); $message->setFrom('*****@*****.**')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**')->addAttachment("mynewattachment.jpg"); $this->assertEquals(get_class($smtp), 'SendGrid\\Smtp'); $this->setExpectedException('Swift_TransportException'); $smtp->send($message); }
function _cdashsendgrid($to, $subject, $body) { global $CDASH_EMAIL_FROM, $CDASH_EMAIL_REPLY, $CDASH_SENDGRID_API_KEY; $sg = new \SendGrid($CDASH_SENDGRID_API_KEY); $mail = new SendGrid\Mail(); $mail->setFrom(new SendGrid\Email(null, $CDASH_EMAIL_FROM)); $mail->setSubject($subject); $mail->setReplyTo(new SendGrid\Email(null, $CDASH_EMAIL_REPLY)); $mail->addContent(new SendGrid\Content('text/plain', $body)); foreach (explode(', ', $to) as $recipient) { $personalization = new SendGrid\Personalization(); $personalization->addTo(new SendGrid\Email(null, $recipient)); $mail->addPersonalization($personalization); } $response = $sg->client->mail()->send()->post($mail); if ($response->statusCode() === 202) { return true; } else { add_log('Failed to send email via sendgrid status code: ' . $response->statusCode(), '_cdashsendgrid', LOG_ERR); return false; } }
public function testFromAccessors() { $message = new SendGrid\Mail(); $message->setFrom("*****@*****.**"); $this->assertEquals("*****@*****.**", $message->getFrom()); }