Some small improvements to email channel management.
This commit is contained in:
parent
c60ee02a4e
commit
7e8b3adc3b
7 changed files with 77 additions and 30 deletions
|
@ -7,8 +7,8 @@ class App.ChannelEmail extends App.ControllerTabs
|
||||||
|
|
||||||
@tabs = [
|
@tabs = [
|
||||||
{
|
{
|
||||||
name: 'Email Accounts',
|
name: 'Accounts',
|
||||||
target: 'c-channel',
|
target: 'c-account',
|
||||||
controller: App.ChannelEmailAccountOverview,
|
controller: App.ChannelEmailAccountOverview,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
<tr data-id="<%- channel.id %>">
|
<tr data-id="<%- channel.id %>">
|
||||||
<td class="<% if channel.status_in is 'ok': %>success<% else if channel.status_in is 'error': %>danger<% else: %>warning<% end %>">
|
<td class="<% if channel.status_in is 'ok': %>success<% else if channel.status_in is 'error': %>danger<% else: %>warning<% end %>">
|
||||||
<%- @T('State') %>: <%- @T(channel.status_in || 'unknown') %><br>
|
<%- @T('State') %>: <%- @T(channel.status_in || 'unknown') %><br>
|
||||||
|
<a href="#" data-type="edit-inbound">
|
||||||
<%= channel.options.inbound.options.user %><br>
|
<%= channel.options.inbound.options.user %><br>
|
||||||
<a href="#" data-type="edit-inbound"><%= channel.options.inbound.options.host %> (<%= channel.options.inbound.adapter %>)</a>
|
<%= channel.options.inbound.options.host %> (<%= channel.options.inbound.adapter %>)
|
||||||
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="<% if channel.status_out is 'ok': %>success<% else if channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
|
<td class="<% if channel.status_out is 'ok': %>success<% else if channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
|
||||||
<%- @T('State') %>: <%- @T(channel.status_out || 'unknown') %><br>
|
<%- @T('State') %>: <%- @T(channel.status_out || 'unknown') %><br>
|
||||||
|
@ -79,9 +81,10 @@
|
||||||
<tr data-id="<%- @channel.id %>">
|
<tr data-id="<%- @channel.id %>">
|
||||||
<td class="<% if @channel.status_out is 'ok': %>success<% else if @channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
|
<td class="<% if @channel.status_out is 'ok': %>success<% else if @channel.status_out is 'error': %>danger<% else: %>warning<% end %>">
|
||||||
<%- @T('State') %>: <%- @T(@channel.status_out || 'unknown') %><br>
|
<%- @T('State') %>: <%- @T(@channel.status_out || 'unknown') %><br>
|
||||||
|
<a href="#" data-type="edit-notification-outbound">
|
||||||
<% if @channel.options.outbound && @channel.options.outbound.options: %>
|
<% if @channel.options.outbound && @channel.options.outbound.options: %>
|
||||||
<%= @channel.options.outbound.options.user %><br>
|
<%= @channel.options.outbound.options.user %><br>
|
||||||
<a href="#" data-type="edit-notification-outbound"><%= @channel.options.outbound.options.host %>
|
<%= @channel.options.outbound.options.host %>
|
||||||
<% end %>
|
<% end %>
|
||||||
(<%= @channel.options.outbound.adapter %>)</a>
|
(<%= @channel.options.outbound.adapter %>)</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -341,10 +341,10 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
|
||||||
inbound: params[:inbound],
|
inbound: params[:inbound],
|
||||||
outbound: params[:outbound],
|
outbound: params[:outbound],
|
||||||
},
|
},
|
||||||
last_log_in: '',
|
last_log_in: nil,
|
||||||
last_log_out: '',
|
last_log_out: nil,
|
||||||
status_in: nil,
|
status_in: 'ok',
|
||||||
status_out: nil,
|
status_out: 'ok',
|
||||||
)
|
)
|
||||||
render json: {
|
render json: {
|
||||||
result: 'ok',
|
result: 'ok',
|
||||||
|
@ -399,6 +399,15 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
|
||||||
|
|
||||||
adapter = params[:adapter].downcase
|
adapter = params[:adapter].downcase
|
||||||
|
|
||||||
|
# validate adapter
|
||||||
|
if adapter !~ /^(smtp|sendmail)$/
|
||||||
|
render json: {
|
||||||
|
result: 'failed',
|
||||||
|
message: "Unknown adapter '#{adapter}'",
|
||||||
|
}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
email = Setting.get('notification_sender')
|
email = Setting.get('notification_sender')
|
||||||
|
|
||||||
# connection test
|
# connection test
|
||||||
|
@ -407,15 +416,6 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
|
||||||
# save settings
|
# save settings
|
||||||
if result[:result] == 'ok'
|
if result[:result] == 'ok'
|
||||||
|
|
||||||
# validate adapter
|
|
||||||
if adapter !~ /^(smtp|sendmail)$/
|
|
||||||
render json: {
|
|
||||||
result: 'failed',
|
|
||||||
message: "Unknown adapter '#{adapter}'",
|
|
||||||
}
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
Channel.where(area: 'Email::Notification').each {|channel|
|
Channel.where(area: 'Email::Notification').each {|channel|
|
||||||
active = false
|
active = false
|
||||||
if adapter =~ /^#{channel.options[:outbound][:adapter]}$/i
|
if adapter =~ /^#{channel.options[:outbound][:adapter]}$/i
|
||||||
|
@ -426,6 +426,8 @@ curl http://localhost/api/v1/channels.json -v -u #{login}:#{password} -H "Conten
|
||||||
options: params[:options],
|
options: params[:options],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
channel.status_out = 'ok'
|
||||||
|
channel.last_log_out = nil
|
||||||
end
|
end
|
||||||
channel.active = active
|
channel.active = active
|
||||||
channel.save
|
channel.save
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
class Channel < ApplicationModel
|
class Channel < ApplicationModel
|
||||||
store :options
|
store :options
|
||||||
|
|
||||||
|
after_create :email_address_check
|
||||||
|
after_update :email_address_check
|
||||||
|
after_destroy :email_address_check
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
fetch all accounts
|
fetch all accounts
|
||||||
|
@ -108,4 +112,12 @@ send via account
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def email_address_check
|
||||||
|
|
||||||
|
# reset non existing channel_ids
|
||||||
|
EmailAddress.channel_cleanup
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,38 @@
|
||||||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
class EmailAddress < ApplicationModel
|
class EmailAddress < ApplicationModel
|
||||||
has_many :groups, after_add: :cache_update, after_remove: :cache_update
|
has_many :groups, after_add: :cache_update, after_remove: :cache_update
|
||||||
belongs_to :channel
|
belongs_to :channel
|
||||||
validates :realname, presence: true
|
validates :realname, presence: true
|
||||||
validates :email, presence: true
|
validates :email, presence: true
|
||||||
|
|
||||||
|
before_create :channel_check
|
||||||
|
before_update :channel_check
|
||||||
|
|
||||||
latest_change_support
|
latest_change_support
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
check and if channel not exists reset configured channels for email addresses
|
||||||
|
|
||||||
|
EmailAddress.channel_cleanup
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.channel_cleanup
|
||||||
|
EmailAddress.all.each {|email_address|
|
||||||
|
next if !email_address.channel_id
|
||||||
|
next if Channel.find_by(id: email_address.channel_id)
|
||||||
|
email_address.channel_id = nil
|
||||||
|
email_address.save
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def channel_check
|
||||||
|
return if Channel.find_by(id: channel_id)
|
||||||
|
self.channel_id = nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,8 +118,8 @@ returns
|
||||||
|
|
||||||
# create EmailAddresses/Channels/Signatures
|
# create EmailAddresses/Channels/Signatures
|
||||||
model_map = {
|
model_map = {
|
||||||
'EmailAddresses' => 'EmailAddress',
|
|
||||||
'Channels' => 'Channel',
|
'Channels' => 'Channel',
|
||||||
|
'EmailAddresses' => 'EmailAddress',
|
||||||
'Signatures' => 'Signature',
|
'Signatures' => 'Signature',
|
||||||
}
|
}
|
||||||
model_map.each {|map_name, model|
|
model_map.each {|map_name, model|
|
||||||
|
|
|
@ -272,20 +272,23 @@ returns on fail
|
||||||
# prepare test email
|
# prepare test email
|
||||||
if subject
|
if subject
|
||||||
mail = {
|
mail = {
|
||||||
:from => email,
|
from: email,
|
||||||
:to => email,
|
to: email,
|
||||||
:subject => "Zammad Getting started Test Email #{subject}",
|
subject: "Zammad Getting started Test Email #{subject}",
|
||||||
:body => "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
|
body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
|
||||||
'x-zammad-ignore' => 'true',
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mail = {
|
mail = {
|
||||||
from: email,
|
from: email,
|
||||||
to: 'emailtrytest@znuny.com',
|
to: 'emailtrytest@znuny.com',
|
||||||
subject: 'This is a Test Email',
|
subject: 'This is a Test Email',
|
||||||
body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.",
|
body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
mail['X-Zammad-Ignore'] = 'true'
|
||||||
|
mail['X-Loop'] = 'yes'
|
||||||
|
mail['Precedence'] = 'bulk'
|
||||||
|
mail['Auto-Submitted'] = 'auto-generated'
|
||||||
|
|
||||||
# test connection
|
# test connection
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in a new issue