Change email address when provisioning


When provisioning a VM from the “lifecycle” button, we are able to change the e-mail address to a fixed one, by following the steps of copying the “email” class for the statemachine and modyfing the default value for the schema from “evmadmin” to the desired one.

We would like to be able to use the “email” value that is entered during the provision itself. But we don’t know how to do it.

Is there any short guide on how to accomplish this? Could you please provide the link or maybe some tip on how to do this task?

Thank you!

If you have a service dialog, try to add ${/#dialog_email} as value to the email address field of your Email class instance.

Thank you xian!!!

Is not a service dialog (at least not one we had created). Is the dialgo that opens by default when clicking the out of the box button of “lifecycle”.

Any clue on how to change it?

The name of the variable is owner_email, you can see it if you examine the different provisioning dialogs.

Methods /ManageIQ/Infrastructure/VM/Provisioning/Email/MiqProvisionRequest_Pending and /ManageIQ/Infrastructure/VM/Provisioning/Email/MiqProvisionRequest_Approved use the requester’s address to send out emails and the instance’s attribute to_email_address as a fallback, examine the code and you’ll see:

to ||= requester_email

# If to is still nil use to_email_address from model
to ||= $evm.object['to_email_address']

/ManageIQ/Infrastructure/VM/Provisioning/Email/MiqProvision_Complete works differently, will send out email to the address of the owner of the VM fetched from VMDB (that might be different than the requester). If not found, will send out to the value set in the instance’s attribute to_email_address:

# Get VM Owner Name and Email
evm_owner_id = vm.attributes['evm_owner_id']
owner = nil
owner = $evm.vmdb('user', evm_owner_id) unless evm_owner_id.nil?
$evm.log("info", "VM Owner: #{owner.inspect}")

to = nil
to = unless owner.nil?
to ||= $evm.object['to_email_address']

If you want to change this behavior, you can copy these methods and make them use owner_email field. The first two methods loads it with

owner_email = miq_request.options[:owner_email] || nil


This is great! Thank you very much!!! I’ll try this out asap :slight_smile: