1

Topic: Trouble with Auto Forwarding via SQL

==== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.7
- Linux/BSD distribution name and version: Ubuntu 16.04
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Apache
- Manage mail accounts with iRedAdmin-Pro? No
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

I have a user who wants all of his emails forwarded (and kept) to another email account I'm not hosting.

I followed the SQL tutorial and used the command:

INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding, active) VALUES ('him@myhosting.com', 'him@somewhereelse.com', 'myhosting.com', 'somewhereelse.com', 1, 1);

followed by a second, similar command to KEEP the emails, per the directions:

INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding, active) VALUES ('him@myhosting.com', 'him@myhosting.com', 'myhosting.com', 'myhosting.com', 1, 1);

on the second command, however, I get the error:
ERROR 1062 (23000): Duplicate entry 'him@myhosting.com-him@myhosting.com' for key 'address'

after this error I typed QUIT to get out (not sure if this commits the changes or threw them away).

So:

1.  What do I do about the error?
2.  Are my changes committed and his emails now ONLY go to the him@somewhereelse.com address?


Andrew

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Trouble with Auto Forwarding via SQL

Answering my own question.

The user gets his emails at both locations - original and forwarded.

This means (I think) that the directions are out of date and the second INSERT statement is unneeded and this command should be removed from the support doc.

Andrew


AndyInNYC wrote:

==== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.7
- Linux/BSD distribution name and version: Ubuntu 16.04
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Apache
- Manage mail accounts with iRedAdmin-Pro? No
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

I have a user who wants all of his emails forwarded (and kept) to another email account I'm not hosting.

I followed the SQL tutorial and used the command:

INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding, active) VALUES ('him@myhosting.com', 'him@somewhereelse.com', 'myhosting.com', 'somewhereelse.com', 1, 1);

followed by a second, similar command to KEEP the emails, per the directions:

INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding, active) VALUES ('him@myhosting.com', 'him@myhosting.com', 'myhosting.com', 'myhosting.com', 1, 1);

on the second command, however, I get the error:
ERROR 1062 (23000): Duplicate entry 'him@myhosting.com-him@myhosting.com' for key 'address'

after this error I typed QUIT to get out (not sure if this commits the changes or threw them away).

So:

1.  What do I do about the error?
2.  Are my changes committed and his emails now ONLY go to the him@somewhereelse.com address?


Andrew

3

Re: Trouble with Auto Forwarding via SQL

Before you ran the SQL commands, the user should have had already forwarding to local mailbox. That first command creates forwarding to external address, but second command returns an error, as there already is a forwarding to local mailbox for the same user.

Looking at the structure of vmail.forwardings table, combination of columns 'address' and 'forwarding' is unique, so while trying to insert the same values again, you will get an error about duplicate entry with the values.

4

Re: Trouble with Auto Forwarding via SQL

And yes, the last part of docs is not very accurate about this, as the local forwarding is enabled by default:
https://docs.iredmail.org/sql.user.mail … mmand-line

5

Re: Trouble with Auto Forwarding via SQL

I added one line to mention this sql duplicate key error:

This SQL record exists by default, but it's a good idea to make sure it exists. If it exists, you will get error like "ERROR 1062 (23000): Duplicate entry 'user@domain.com-user@domain.com' for key 'address'", don't panic.

I hope it's clear now. big_smile

Thank you all for the feedback.