Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 6404 smtp2 go messaging adapter #51

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Stage 1: Composer
FROM composer:2.0 as composer

ARG TESTING=false
Expand All @@ -15,11 +16,14 @@ RUN composer install \
--no-scripts \
--prefer-dist

# Stage 2: PHP
FROM php:8.0-cli-alpine

WORKDIR /usr/local/src/

COPY --from=composer /usr/local/src/vendor /usr/local/src/vendor
COPY . /usr/local/src/

CMD [ "tail", "-f", "/dev/null" ]


CMD [ "tail", "-f", "/dev/null" ]
179 changes: 90 additions & 89 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ version: '3.9'

services:
tests:

environment:
- SMTP2GO_USERNAME
- SMTP2GO_PASSWORD
- SMTP2GO_SERVER
- SMTP2GO_PORT
- MAILGUN_API_KEY
- MAILGUN_DOMAIN
- SENDGRID_API_KEY
Expand All @@ -29,6 +34,7 @@ services:
- VONAGE_API_SECRET
- VONAGE_TO
- VONAGE_FROM

build:
context: .
volumes:
Expand All @@ -44,4 +50,4 @@ services:
request-catcher:
image: appwrite/requestcatcher:1.0.0
ports:
- '10001:5000'
- '10001:5000'
8 changes: 0 additions & 8 deletions src/Utopia/Messaging/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ abstract class Adapter
{
/**
* Get the name of the adapter.
*
* @return string
*/
abstract public function getName(): string;

/**
* Get the type of the adapter.
*
* @return string
*/
abstract public function getType(): string;

/**
* Get the type of the message the adapter can send.
*
* @return string
*/
abstract public function getMessageType(): string;

/**
* Get the maximum number of messages that can be sent in a single request.
*
* @return int
*/
abstract public function getMaxMessagesPerRequest(): int;

Expand Down
4 changes: 0 additions & 4 deletions src/Utopia/Messaging/Adapters/Email/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public function __construct(

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -30,8 +28,6 @@ public function getName(): string

/**
* Get adapter description.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
Expand Down
6 changes: 0 additions & 6 deletions src/Utopia/Messaging/Adapters/Email/Sendgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public function __construct(private string $apiKey)

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -27,8 +25,6 @@ public function getName(): string

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
Expand All @@ -38,8 +34,6 @@ public function getMaxMessagesPerRequest(): int
/**
* {@inheritdoc}
*
* @param Email $message
* @return string
*
* @throws Exception
*/
Expand Down
53 changes: 53 additions & 0 deletions src/Utopia/Messaging/Adapters/Email/Smtp2go.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Utopia\Messaging\Adapters\Email;

use PHPMailer\PHPMailer\PHPMailer;
use Utopia\Messaging\Adapters\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email;

class Smtp2go extends EmailAdapter
{
public function getName(): string
{
return 'SMTP2GO';
}

public function getMaxMessagesPerRequest(): int
{
return 1; // SMTP2GO typically sends one email at a time
}

protected function process(Email $message): string
{
// Retrieve SMTP server details from environment variables
$smtpUsername = getenv('SMTP2GO_USERNAME');
$smtpPassword = getenv('SMTP2GO_PASSWORD');
$smtpServer = getenv('SMTP2GO_SERVER');
$smtpPort = getenv('SMTP2GO_PORT');

// Create a PHPMailer instance
$mailer = new PHPMailer();

// Configure SMTP settings
$mailer->isSMTP();
$mailer->Username = $smtpUsername;
$mailer->Password = $smtpPassword;
$mailer->Host = $smtpServer;
$mailer->Port = $smtpPort;
$mailer->SMTPAuth = true;

// Set email content
$mailer->setFrom('Senders-email', 'Name');
$mailer->addAddress('Receivers-email', 'Name');
$mailer->Subject = 'Test Subject';
$mailer->Body = 'Test mail';

// Send the email
if ($mailer->send()) {
return 'Email sent successfully';
} else {
return 'Failed to send email: '.$mailer->ErrorInfo;
}
}
}
12 changes: 0 additions & 12 deletions src/Utopia/Messaging/Adapters/Push/APNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
class APNS extends PushAdapter
{
/**
* @param string $authKey
* @param string $authKeyId
* @param string $teamId
* @param string $bundleId
* @param string $endpoint
* @return void
*/
public function __construct(
Expand All @@ -27,8 +22,6 @@ public function __construct(

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -37,8 +30,6 @@ public function getName(): string

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
Expand All @@ -48,8 +39,6 @@ public function getMaxMessagesPerRequest(): int
/**
* {@inheritdoc}
*
* @param Push $message
* @return string
*
* @throws Exception
*/
Expand Down Expand Up @@ -179,7 +168,6 @@ function ($value) {
/**
* Generate JWT.
*
* @return string
*
* @throws Exception
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Utopia/Messaging/Adapters/Push/FCM.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public function __construct(

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -27,8 +25,6 @@ public function getName(): string

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
Expand Down
18 changes: 0 additions & 18 deletions src/Utopia/Messaging/Messages/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,31 @@ public function __construct(
) {
}

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove a bunch of comments in unrelated files?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the composer lint command and then it removed the comments to resolve the linting errors issue. @gewenyu99

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

????? Really

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the composer lint command and then it removed the comments to resolve the linting errors issue.

That doesn't quite make sense...composer lint only checks for lint errors. it shouldn't be modifying anything.

Copy link
Author

@Ayaan49 Ayaan49 Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint error
@stnguyen90 @gewenyu99 Sorry, it was composer format not composer lint. composer format removed those comments because it was causing linting error. However, my files are not causing any linting error.

* @return array
*/
public function getTo(): array
{
return $this->to;
}

/**
* @return string
*/
public function getSubject(): string
{
return $this->subject;
}

/**
* @return string
*/
public function getContent(): string
{
return $this->content;
}

/**
* @return string|null
*/
public function getFrom(): ?string
{
return $this->from;
}

/**
* @return array|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}

/**
* @return bool
*/
public function isHtml(): bool
{
return $this->html;
Expand Down
30 changes: 0 additions & 30 deletions src/Utopia/Messaging/Messages/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function __construct(
) {
}

/**
* @return array
*/
public function getTo(): array
{
return $this->to;
Expand All @@ -45,73 +42,46 @@ public function getFrom(): ?string
return null;
}

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @return string
*/
public function getBody(): string
{
return $this->body;
}

/**
* @return array|null
*/
public function getData(): ?array
{
return $this->data;
}

/**
* @return string|null
*/
public function getAction(): ?string
{
return $this->action;
}

/**
* @return string|null
*/
public function getSound(): ?string
{
return $this->sound;
}

/**
* @return string|null
*/
public function getIcon(): ?string
{
return $this->icon;
}

/**
* @return string|null
*/
public function getColor(): ?string
{
return $this->color;
}

/**
* @return string|null
*/
public function getTag(): ?string
{
return $this->tag;
}

/**
* @return string|null
*/
public function getBadge(): ?string
{
return $this->badge;
Expand Down
Loading