From f59005ad352234f7020f0ef3d0d7f45e67b8118e Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 2 Nov 2018 09:36:50 -0700 Subject: [PATCH] Fix sender email address for invoicing alerts It was failing to send alert emails because the email address it was constructing did not have permission through GAE to send emails. This switches it over to using the send from email address already in use elsewhere in the app that does successfully send emails. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219812019 --- java/google/registry/config/RegistryConfig.java | 14 -------------- .../registry/config/RegistryConfigSettings.java | 1 - .../registry/config/files/default-config.yaml | 6 +++--- .../reporting/billing/BillingEmailUtils.java | 10 +++++----- .../reporting/icann/ReportingEmailUtils.java | 2 +- .../reporting/spec11/Spec11EmailUtils.java | 10 +++++----- 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index 813946e75..551a7d184 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -827,20 +827,6 @@ public final class RegistryConfig { return config.misc.alertRecipientEmailAddress; } - /** - * Returns the email address we send emails from. - * - * @see google.registry.reporting.icann.ReportingEmailUtils - * @see google.registry.reporting.billing.BillingEmailUtils - * @see google.registry.reporting.spec11.Spec11EmailUtils - */ - @Provides - @Config("alertSenderEmailAddress") - public static String provideAlertSenderEmailAddress( - @Config("projectId") String projectId, RegistryConfigSettings config) { - return String.format("%s-no-reply@%s", projectId, config.misc.alertEmailSenderDomain); - } - /** * Returns the email address to which spec 11 email should be replied. * diff --git a/java/google/registry/config/RegistryConfigSettings.java b/java/google/registry/config/RegistryConfigSettings.java index 2449c1c58..404ce1254 100644 --- a/java/google/registry/config/RegistryConfigSettings.java +++ b/java/google/registry/config/RegistryConfigSettings.java @@ -161,7 +161,6 @@ public class RegistryConfigSettings { public String sheetExportId; public String alertRecipientEmailAddress; public String spec11ReplyToEmailAddress; - public String alertEmailSenderDomain; public int asyncDeleteDelaySeconds; } diff --git a/java/google/registry/config/files/default-config.yaml b/java/google/registry/config/files/default-config.yaml index 85fe99625..b5deec22f 100644 --- a/java/google/registry/config/files/default-config.yaml +++ b/java/google/registry/config/files/default-config.yaml @@ -22,6 +22,9 @@ gSuite: domainName: domain-registry.example # Display name and email address used on outgoing emails through G Suite. + # The email address must be valid and have permission in the GAE app to send + # emails. For more info see: + # https://cloud.google.com/appengine/docs/standard/java/mail/#who_can_send_mail outgoingEmailDisplayName: Example Registry outgoingEmailAddress: noreply@project-id.appspotmail.com @@ -343,9 +346,6 @@ misc: # to be a deliverable email address in case the registrars want to contact us. spec11ReplyToEmailAddress: reply-to@example.com - # Domain for the email address we send alert summary emails from. - alertEmailSenderDomain: appspotmail.com - # How long to delay processing of asynchronous deletions. This should always # be longer than eppResourceCachingSeconds, to prevent deleted contacts or # hosts from being used on domains. diff --git a/java/google/registry/reporting/billing/BillingEmailUtils.java b/java/google/registry/reporting/billing/BillingEmailUtils.java index ae91c7981..918074949 100644 --- a/java/google/registry/reporting/billing/BillingEmailUtils.java +++ b/java/google/registry/reporting/billing/BillingEmailUtils.java @@ -44,7 +44,7 @@ class BillingEmailUtils { private final SendEmailService emailService; private final YearMonth yearMonth; - private final String alertSenderAddress; + private final String outgoingEmailAddress; private final String alertRecipientAddress; private final ImmutableList invoiceEmailRecipients; private final String billingBucket; @@ -56,7 +56,7 @@ class BillingEmailUtils { BillingEmailUtils( SendEmailService emailService, YearMonth yearMonth, - @Config("alertSenderEmailAddress") String alertSenderAddress, + @Config("gSuiteOutgoingEmailAddress") String outgoingEmailAddress, @Config("alertRecipientEmailAddress") String alertRecipientAddress, @Config("invoiceEmailRecipients") ImmutableList invoiceEmailRecipients, @Config("billingBucket") String billingBucket, @@ -65,7 +65,7 @@ class BillingEmailUtils { Retrier retrier) { this.emailService = emailService; this.yearMonth = yearMonth; - this.alertSenderAddress = alertSenderAddress; + this.outgoingEmailAddress = outgoingEmailAddress; this.alertRecipientAddress = alertRecipientAddress; this.invoiceEmailRecipients = invoiceEmailRecipients; this.billingBucket = billingBucket; @@ -86,7 +86,7 @@ class BillingEmailUtils { new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile); try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) { Message msg = emailService.createMessage(); - msg.setFrom(new InternetAddress(alertSenderAddress)); + msg.setFrom(new InternetAddress(outgoingEmailAddress)); for (String recipient : invoiceEmailRecipients) { msg.addRecipient(RecipientType.TO, new InternetAddress(recipient)); } @@ -126,7 +126,7 @@ class BillingEmailUtils { retrier.callWithRetry( () -> { Message msg = emailService.createMessage(); - msg.setFrom(new InternetAddress(alertSenderAddress)); + msg.setFrom(new InternetAddress(outgoingEmailAddress)); msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress)); msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth.toString())); msg.setText(body); diff --git a/java/google/registry/reporting/icann/ReportingEmailUtils.java b/java/google/registry/reporting/icann/ReportingEmailUtils.java index 9b248f94d..c011b8bfa 100644 --- a/java/google/registry/reporting/icann/ReportingEmailUtils.java +++ b/java/google/registry/reporting/icann/ReportingEmailUtils.java @@ -25,7 +25,7 @@ import javax.mail.internet.InternetAddress; /** Static utils for emailing reporting results. */ public class ReportingEmailUtils { - @Inject @Config("alertSenderEmailAddress") String sender; + @Inject @Config("gSuiteOutgoingEmailAddress") String sender; @Inject @Config("alertRecipientEmailAddress") String recipient; @Inject SendEmailService emailService; @Inject ReportingEmailUtils() {} diff --git a/java/google/registry/reporting/spec11/Spec11EmailUtils.java b/java/google/registry/reporting/spec11/Spec11EmailUtils.java index 76b716446..c29e2003b 100644 --- a/java/google/registry/reporting/spec11/Spec11EmailUtils.java +++ b/java/google/registry/reporting/spec11/Spec11EmailUtils.java @@ -45,7 +45,7 @@ public class Spec11EmailUtils { private final SendEmailService emailService; private final YearMonth yearMonth; - private final String alertSenderAddress; + private final String outgoingEmailAddress; private final String alertRecipientAddress; private final String spec11ReplyToAddress; private final String reportingBucket; @@ -58,7 +58,7 @@ public class Spec11EmailUtils { Spec11EmailUtils( SendEmailService emailService, YearMonth yearMonth, - @Config("alertSenderEmailAddress") String alertSenderAddress, + @Config("gSuiteOutgoingEmailAddress") String outgoingEmailAddress, @Config("alertRecipientEmailAddress") String alertRecipientAddress, @Config("spec11ReplyToEmailAddress") String spec11ReplyToAddress, @Config("spec11EmailBodyTemplate") String spec11EmailBodyTemplate, @@ -68,7 +68,7 @@ public class Spec11EmailUtils { Retrier retrier) { this.emailService = emailService; this.yearMonth = yearMonth; - this.alertSenderAddress = alertSenderAddress; + this.outgoingEmailAddress = outgoingEmailAddress; this.alertRecipientAddress = alertRecipientAddress; this.spec11ReplyToAddress = spec11ReplyToAddress; this.reportingBucket = reportingBucket; @@ -135,7 +135,7 @@ public class Spec11EmailUtils { msg.setSubject( String.format("Google Registry Monthly Threat Detector [%s]", yearMonth.toString())); msg.setText(body.toString()); - msg.setFrom(new InternetAddress(alertSenderAddress)); + msg.setFrom(new InternetAddress(outgoingEmailAddress)); msg.addRecipient(RecipientType.TO, new InternetAddress(registrarEmail)); msg.addRecipient(RecipientType.BCC, new InternetAddress(spec11ReplyToAddress)); emailService.sendMessage(msg); @@ -147,7 +147,7 @@ public class Spec11EmailUtils { retrier.callWithRetry( () -> { Message msg = emailService.createMessage(); - msg.setFrom(new InternetAddress(alertSenderAddress)); + msg.setFrom(new InternetAddress(outgoingEmailAddress)); msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress)); msg.setSubject(subject); msg.setText(body);