{"id":24552988,"url":"https://github.com/npdeehan/sendemailcamunda7example","last_synced_at":"2025-03-16T14:15:10.190Z","repository":{"id":90222894,"uuid":"439003005","full_name":"NPDeehan/SendEmailCamunda7Example","owner":"NPDeehan","description":"This is an example of how you can send an Email using Camunda and an External Task","archived":false,"fork":false,"pushed_at":"2022-01-04T15:31:04.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T01:34:33.827Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NPDeehan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-16T13:40:50.000Z","updated_at":"2022-04-20T18:08:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"672535f9-46f2-4308-80a1-c614ddfd7c52","html_url":"https://github.com/NPDeehan/SendEmailCamunda7Example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NPDeehan%2FSendEmailCamunda7Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NPDeehan%2FSendEmailCamunda7Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NPDeehan%2FSendEmailCamunda7Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NPDeehan%2FSendEmailCamunda7Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NPDeehan","download_url":"https://codeload.github.com/NPDeehan/SendEmailCamunda7Example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878491,"owners_count":20362433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-23T01:33:47.072Z","updated_at":"2025-03-16T14:15:10.174Z","avatar_url":"https://github.com/NPDeehan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Send Email External Task Example\n\nThis example shows how an External Task can connect to Camunda and send an email when a process reaches a service task with the `SendEmail` Topic\n\n## Running the Project\nRunning the project has 3 pretty simple steps\n1. Download and Run Camunda\n1. Configure and Startup The Worker\n1. Deploy the Send Email Process\n\nBelow I'll describe each step in detail if you aren't already aware of how Camunda projects generally work. \n\n### **Download and Run Camunda**\n\nSimply go to the [Camunda.com and download](https://camunda.com/download/) the latest version of Camunda Run. \n\nUnzip the contents into a folder and run the `start.bat` or `start.sh` file depending on your operating system \n\n\n### **Configure and Startup The Worker**\n\nThe most important part of the worker to understand is the `SendEmailHandler.java` file. This is where all the work is done.\n\nIt work by subscribing to a *Topic* and when tasks for that topic are picked up it will send an email. This line shows that the worker is subscribed to the `SendEmail` Topic \n\n```java\n@ExternalTaskSubscription(\"SendEmail\") \n```\n\nwhen it starts up it will send a request to Camunda asking for any tasks with that topic. \n\nWhen it finds one it will attempt to send an email. \n\nThere are three possible outcomes if the works tries to send an email. \n\n1. **Email Send Successfully**\n\nIf nothing goes wrong and the email is successfully send the worker will contact the engine to say that the task has been completed with the following method\n\n```java\nexternalTaskService.complete(externalTask);\n```\n\n2. **Email Address is invalid**\n\nThe worker runs some basic validation on the sending and reiving email addresses and if either of those are found to be invalid it tells the Engine that throwing BPMN Error which can be caught so that a user can manually correct the email address. This done with the following method\n\n```Java\nexternalTaskService.handleBpmnError(externalTask, \n          \"INVALID_EMAIL\",\n          \"The email address(s) \" + \n          invalidEmailAddresses + \n          \" found to be invalid\");\n```\n\nThe method not only throws a specific error called `INVALID_EMAIL` but it also sends a message containing a list of the invalid email addresses that it's found. \n\n3. **Email fails to send for technical reason**\n\nIf a technical error occurs, (e.g. the email server is down) it will return with a failure. This is a way of alerting an admin to the problem by telling the engine to create an incident. \n\n```java\n externalTaskService.handleFailure(externalTask, \n        \"Email not Sent!\", \n        e.getMessage(), \n        0, \n        0);\n```  \n\nThe configuration for the worker is all contained in the `application.yml` file and before you start up the worker you need to add some additional configuration to it so that it can send out an email.\n\n```yml\nspring.mail:\n  host: smtp.gmail.com\n  port: 587\n  username: yourEmail@gmail.com\n  password: yourPassword\n  properties.mail.smtp:\n    auth: true\n    starttls.enable: true\n\n```\nOnce you're added the details of your email server you can run the `Application.java` file within your IDE.\n\nThe worker will then connect to Camunda looking for work related to the `SendEmail` Topic\n\n### **Deploy Email Process**\n\n![alt](./ExampleProcess/SendEmailExample.png)\n\nIf you use this worker for any process but i've included a demo process to make it easy to test it out.\n\nYou just need to download the Camunda Modeler and open the `./ExampleProcess/SendEmailExample.bpmn` file. You can then deploy this file directly from the modeler. To do this click on the deploy button at the bottom and make sure you add the `EmailDetailsForm.form` to the deployment. This is in the same folder as the model. \n\nIf you've deployed it successfully you should be able to go to\n`http://localhost:8080/camunda/app/tasklist/default/` log in with `demo/demo` and then you can start the process, complete the form and the email should be sent out.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpdeehan%2Fsendemailcamunda7example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpdeehan%2Fsendemailcamunda7example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpdeehan%2Fsendemailcamunda7example/lists"}