@Override
  public void sendEmailAddressChangedNotification(OrcidProfile updatedProfile, Email oldEmail) {

    // build up old template
    Map<String, Object> templateParams = new HashMap<String, Object>();

    String subject = getSubject("email.subject.email_removed", updatedProfile);
    String email = oldEmail.getValue();
    String emailFriendlyName = deriveEmailFriendlyName(updatedProfile);
    templateParams.put("emailName", emailFriendlyName);
    String verificationUrl =
        createVerificationUrl(
            updatedProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(),
            orcidUrlManager.getBaseUrl());
    templateParams.put("verificationUrl", verificationUrl);
    templateParams.put("oldEmail", oldEmail.getValue());
    templateParams.put(
        "newEmail",
        updatedProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue());
    templateParams.put("orcid", updatedProfile.getOrcidIdentifier().getPath());
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);

    addMessageParams(templateParams, updatedProfile);

    // Generate body from template
    String body = templateManager.processTemplate("email_removed.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("email_removed_html.ftl", templateParams);

    mailGunManager.sendEmail(EMAIL_CHANGED_NOTIFY_ORCID_ORG, email, subject, body, html);
  }
 /**
  * Creates a minimal record
  *
  * @param orcidProfile The record to create
  * @return the new record
  */
 private OrcidProfile createMinimalProfile(OrcidProfile orcidProfile, boolean usedCaptcha) {
   OrcidProfile minimalProfile =
       orcidProfileManager.createOrcidProfile(orcidProfile, false, usedCaptcha);
   // Set source to the new email
   String sourceId = minimalProfile.getOrcidIdentifier().getPath();
   List<Email> emails = minimalProfile.getOrcidBio().getContactDetails().getEmail();
   for (Email email : emails) emailManager.addSourceToEmail(email.getValue(), sourceId);
   LOGGER.debug(
       "Created minimal orcid and assigned id of {}", orcidProfile.getOrcidIdentifier().getPath());
   return minimalProfile;
 }
  @Override
  public void sendDelegationRequestEmail(OrcidProfile managed, OrcidProfile trusted, String link) {
    // Create map of template params
    String orcid = managed.getOrcidIdentifier().getPath();
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("link", link);

    String trustedOrcidValue = trusted.retrieveOrcidPath();
    String managedOrcidValue = managed.retrieveOrcidPath();
    String emailNameForDelegate = deriveEmailFriendlyName(managed);
    String trustedOrcidName = deriveEmailFriendlyName(trusted);
    templateParams.put("emailNameForDelegate", emailNameForDelegate);
    templateParams.put("trustedOrcidName", trustedOrcidName);
    templateParams.put("trustedOrcidValue", trustedOrcidValue);
    templateParams.put("managedOrcidValue", managedOrcidValue);

    Email primaryEmail = managed.getOrcidBio().getContactDetails().retrievePrimaryEmail();
    if (primaryEmail == null) {
      LOGGER.info("Cant send admin delegate email if primary email is null: {}", orcid);
      return;
    }

    addMessageParams(templateParams, managed);

    String htmlBody =
        templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);

    // Send message
    if (apiRecordCreationEmailEnabled) {
      String subject = getSubject("email.subject.admin_as_delegate", managed, trustedOrcidName);
      ProfileEntity trustedProfileEntity = profileDao.find(trusted.getOrcidIdentifier().getPath());
      boolean notificationsEnabled =
          trustedProfileEntity != null ? trustedProfileEntity.getEnableNotifications() : false;
      if (notificationsEnabled) {
        NotificationCustom notification = new NotificationCustom();
        notification.setNotificationType(NotificationType.CUSTOM);
        notification.setSubject(subject);
        notification.setBodyHtml(htmlBody);
        createNotification(managed.getOrcidIdentifier().getPath(), notification);
      } else {
        mailGunManager.sendEmail(
            DELEGATE_NOTIFY_ORCID_ORG, primaryEmail.getValue(), subject, null, htmlBody);
      }
      profileEventDao.persist(
          new ProfileEventEntity(orcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
    } else {
      LOGGER.debug(
          "Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}",
          htmlBody);
    }
  }
  @Override
  public void sendClaimReminderEmail(OrcidProfile orcidProfile, int daysUntilActivation) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(orcidProfile));
    String orcid = orcidProfile.getOrcidIdentifier().getPath();
    templateParams.put("orcid", orcid);
    templateParams.put("subject", getSubject("email.subject.claim_reminder", orcidProfile));
    Source source = orcidProfile.getOrcidHistory().getSource();
    String creatorName = "";
    if (source != null) {
      if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
        creatorName = source.getSourceName().getContent();
      } else {
        creatorName = source.retrieveSourcePath();
      }
    }
    templateParams.put("creatorName", creatorName);
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("daysUntilActivation", daysUntilActivation);
    Email primaryEmail = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail();
    if (primaryEmail == null) {
      LOGGER.info("Cant send claim reminder email if primary email is null: {}", orcid);
      return;
    }
    String verificationUrl =
        createClaimVerificationUrl(primaryEmail.getValue(), orcidUrlManager.getBaseUrl());
    templateParams.put("verificationUrl", verificationUrl);

    addMessageParams(templateParams, orcidProfile);

    String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
    // Generate body from template
    String body = templateManager.processTemplate("claim_reminder_email.ftl", templateParams);
    String htmlBody =
        templateManager.processTemplate("claim_reminder_email_html.ftl", templateParams);

    // Send message
    if (apiRecordCreationEmailEnabled) {
      mailGunManager.sendEmail(
          CLAIM_NOTIFY_ORCID_ORG,
          email,
          getSubject("email.subject.claim_reminder", orcidProfile),
          body,
          htmlBody);
      profileEventDao.persist(new ProfileEventEntity(orcid, ProfileEventType.CLAIM_REMINDER_SENT));
    } else {
      LOGGER.debug(
          "Not sending claim reminder email, because API record creation email option is disabled. Message would have been: {}",
          body);
    }
  }