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

MBS-13719: Integrate new mail service into MusicBrainz Server #3363

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
71 changes: 32 additions & 39 deletions lib/MusicBrainz/Server/Email.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,6 @@ sub _create_email
});
}

sub _create_email_verification_email
{
my ($self, %opts) = @_;

my @headers = (
'To' => $opts{email},
'From' => $EMAIL_NOREPLY_ADDRESS,
'Reply-To' => $EMAIL_SUPPORT_ADDRESS,
'Message-Id' => _message_id('verify-email-%d', time()),
'Subject' => 'Please verify your email address',
);

my $verification_link = $opts{verification_link};
my $ip = $opts{ip};
my $user_name = $opts{editor}->name;

my $body = <<"EOS";
Hello $user_name,

This is a verification email for your MusicBrainz account. Please click
on the link below to verify your email address:

$verification_link

If clicking the link above doesn't work, please copy and paste the URL in a
new browser window instead.

This email was triggered by a request from the IP address [$ip].

Thanks for using MusicBrainz!

-- The MusicBrainz Team
EOS

return $self->_create_email(\@headers, $body);
}

sub _create_email_in_use_email
{
my ($self, %opts) = @_;
Expand Down Expand Up @@ -452,9 +415,39 @@ sub send_message_to_editor
sub send_email_verification
{
my ($self, %opts) = @_;
my $_url = $mail_service_base_url . "/send_single";

my $email = $self->_create_email_verification_email(%opts);
return $self->_send_email($email);
my $ip = $opts{ip};
my $to_name = $opts{editor}->name;
my $verification_link = $opts{verification_link};

if(blessed($verification_link) && $verification_link->can('as_string')) {
$verification_link = $verification_link->as_string;
}

my $body = {
'template_id' => 'verify-email',
'to' => $opts{email},
'from' => $EMAIL_NOREPLY_ADDRESS,
# 'lang'
'message_id' => _message_id('verify-email-%d', time()),
'reply_to' => $EMAIL_NOREPLY_ADDRESS,
'params' => {
'to_name' => $to_name,
'verification_url' => "$verification_link",
Copy link
Member

Choose a reason for hiding this comment

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

If this is already a string, why stringify it again?

FWIW, at least locally the string does not seem to be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That issue seems to have resolved itself. I believe it was because it was because bitmap and I were testing with an older version of the Mail service image 🤷. The reason for the two methods of stringification was effectively me throwing stuff at the wall to see what stuck - I can probably remove the first one now.

'ip' => $ip
}
};

my $header_params = {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
};

my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($body));
if (! $res->is_success) {
print "Failed to send!"
}
}

sub send_email_in_use
Expand Down