Action
Create mailboxes and email addresses
Create Webfaction mailboxes and email addresses
Takes each line of a draft in the format:
email address,mailbox
email address,mailbox
and creates the mailbox, then the email address (using the mailbox as its target)
The original draft is updated with the results of the API calls. Fully successful lines
will have the mailbox passowrd (randomly generated by the API) added to the end of the
line along with a success message.
If a failure occurs the error message is appended to the end of the line
If a mailbox is created, but not the associated email address the mailbox is left intact
Steps
-
script
// Create Webfaction mailboxes and email addresses // // Takes each line of a draft in the format: // // <email address>,<mailbox> // <email address>,<mailbox> // // and creates the mailbox, then the email address (using the mailbox as its target) // // The original draft is updated with the results of the API calls. Fully successful lines // will have the mailbox passowrd (randomly generated by the API) added to the end of the // line along with a success message. // If a failure occurs the error message is appended to the end of the line // If a mailbox is created, but not the associated email address the mailbox is left intact const url = "https://api.webfaction.com/"; function API_login(username,password) { let methodName = "login"; let params = [username,password]; return XMLRPC.request(url, methodName, params); } function API_createMailbox(sessionID,mailbox) { let methodName = "create_mailbox"; let params = [sessionID,mailbox,false]; return XMLRPC.request(url, methodName, params); } function API_createEmail(sessionID,emailAddress,mailbox) { let methodName = "create_email"; let params = [sessionID,emailAddress,mailbox]; return XMLRPC.request(url, methodName, params); } var credential = Credential.createWithUsernamePassword("Webfaction", "Webfaction API"); var result = credential.authorize(); if (!result) { alert("Failed to obtain credentials. Please check and retry"); context.cancel("Failed to obtain credentials"); } else { let response = API_login(credential.getValue("username"),credential.getValue("password")); if (response.success) { sessionID = response.params[0][0]; var newDraft = ""; var d=draft.content; var lines = d.split("\n"); for (var line of lines) { fields = line.split(","); if (fields.length == 2) { let response = API_createMailbox(sessionID,fields[1]); if (response.success) { let newLine=`${line},${response.params[0]["password"]}`; let response2 = API_createEmail(sessionID,fields[0],fields[1]); if (response2.success) { newDraft+= `${newLine} - Success\n`; } else { newDraft+= `${newLine} - Fault: ${response2.faultCode} + ${response2.error}\n`; } } else { newDraft+= `${line} - Fault: ${response.faultCode} + ${response.error}\n`; context.fail(); } } else { newDraft+=`${line} - Bad line\n`; } } draft.content = newDraft; draft.update(); } else { alert("Fault: " + response.faultCode + ", " + response.error); context.fail(); } }
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.