Skip to content

WIP: Add Sending Mail Possibility to Mesh #1357

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

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft

Conversation

dajenacuko
Copy link
Contributor

Abstract

Checklist

General

  • Added abstract that describes the change
  • Added changelog entry to /CHANGELOG.adoc
  • Ensured that the change is covered by tests
  • Ensured that the change is documented in the docs

On API Changes

  • Checked if the changes are breaking or not
  • Added GraphQL API if applicable
  • Added Elasticsearch mapping if applicable
@dajenacuko dajenacuko marked this pull request as draft April 12, 2022 08:25
@dajenacuko dajenacuko requested a review from plyhun April 12, 2022 08:25
@@ -137,6 +137,18 @@ public abstract class MeshOptions implements Option {
@EnvironmentVariable(name = MESH_MAX_PURGE_BATCH_SIZE, description = "Override the maximum purge batch size.")
private int versionPurgeMaxBatchSize = 10;

public MailOptions getMailOptions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use @JsonProperty("mail") or similar.

@@ -137,6 +137,18 @@ public abstract class MeshOptions implements Option {
@EnvironmentVariable(name = MESH_MAX_PURGE_BATCH_SIZE, description = "Override the maximum purge batch size.")
private int versionPurgeMaxBatchSize = 10;

public MailOptions getMailOptions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use @JsonProperty("mail") or similar.

message.setAttachment(new ArrayList<>());

// download all binary data and add as attachments
return Observable.fromIterable(fileFieldNames).flatMapSingle(name -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use BinaryDao to get the binary stream asynchronously.

message.setAttachment(new ArrayList<>());

// download all binary data and add as attachments
return Observable.fromIterable(fileFieldNames).flatMapSingle(name -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use BinaryDao to get the binary stream asynchronously.

@plyhun
Copy link
Contributor

plyhun commented Apr 13, 2022

Good work by now, thanks. Keep making it 👍

1 similar comment
@plyhun
Copy link
Contributor

plyhun commented Apr 13, 2022

Good work by now, thanks. Keep making it 👍

HibJob mailSendingJob = Tx.get().jobDao().enqueueMailSending(user, new Timestamp(System.currentTimeMillis()).getTime(), ac.getBodyAsString());

if(mailSendingJob.getStatus() == JobStatus.FAILED){
Tx.get().jobDao().enqueueMailSending(user,new Timestamp(System.currentTimeMillis()).getTime() + meshOptions.getMailOptions().getRetry(), ac.getBodyAsString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you have to reassign mailSendingJob, in order the following status check to work.

Tx.get().jobDao().enqueueMailSending(user,new Timestamp(System.currentTimeMillis()).getTime() + meshOptions.getMailOptions().getRetry(), ac.getBodyAsString());
}
if (mailSendingJob.getStatus() == JobStatus.COMPLETED) {
Tx.get().jobDao().delete(mailSendingJob, new DummyBulkActionContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

And here you have to reassign it again to get the eventual status, and return it appropriately.

import io.vertx.ext.web.FileUpload;

/**
* @see MicronodeMigrationContext
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a micronode but a general action context.

MailClient mailClient = MailClient.create(vertx, config);
String mail = db.tx(mailJob::getMail);

MailSendingRequest request = JsonUtil.readValue(mail, MailSendingRequest.class);
Copy link
Contributor

@plyhun plyhun May 3, 2022

Choose a reason for hiding this comment

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

These approach of having the whole email as JSON is not that much useful. Better to send/store the mail parts distinctly, as done in the sending context. This will allow the client to fetch/filter/reuse the jobs, if required, and gives better control over sending.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that I have also data that cannot be send in primitive data like Lists of Strings for example

});
})
.lastOrError().doOnError(th-> {

Copy link
Contributor

Choose a reason for hiding this comment

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

Please fill the error processing.

* @param mail
* @return
*/
HibJob enqueueMailSending(HibUser user, long now, String mail);
Copy link
Contributor

Choose a reason for hiding this comment

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

The API should also be changed accordingly, to accept distinct email parts.

Copy link
Contributor

Choose a reason for hiding this comment

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

HibJob enququeMailSending(HibUser user, long time, List<String> toAddrs, List<String> ccAddrs, List<String> bccAddrs, String title, String body, List<String> attachmentUuids)

Copy link
Contributor

Choose a reason for hiding this comment

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

HibJob enququeMailSending(HibUser user, long time, MailSendingRequest request)


import com.gentics.mesh.core.rest.common.AbstractResponse;

public class MailSendingRequest extends AbstractResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a response, not a request.

Copy link
Contributor

@plyhun plyhun left a comment

Choose a reason for hiding this comment

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

Good looking in general. I'd ask to change the sending and storage API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants