1

I am on a mac using terminal. I am trying to redirect email from a work email to gmail (the work email only allows IMAP and gmail can only fetch from POP - hence the workaround).

I have successfully configured fetchmail to fetch the mail from the work email.

I would now like to REDIRECT it to gmail, such that when it arrives it appears to arrive from (and I can reply to) the original sender.

I have tried both procmail and ssmtp with following configurations. For BOTH, the email does arrive in my gmail inbox however it appears to come from ME myusername@gmail.com rather than the original sender.

Any suggestions? I am very new at this. Welcome suggestions using procmail or ssmtp (or if it will work anything else!)

procmail set up

.fetchmailrc file:

set no bouncemail
poll outlook.office365.com with protocol imap
port 993
auth password
user user@domain.com password password
ssl
sslfingerprint "<Correct Fingerprint - not sure if I should copy this here>"
sslcertpath /Users/myuser/.certs
keep
no rewrite
mda "/usr/local/bin/procmail -f %F -d %T";

.procmailrc file

VERBOSE=yes
:0
! myusername@gmail.com

(with sendmail configured to send from my gmail, as per my answer here: Using procmail to forward to gmail)

ssmtp set up

/opt/local/etc/ssmtp/ssmtp.conf file

root=FIXME@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=localhost
UseTLS=Yes
UseSTARTTLS=Yes
AuthUser=FIXME@gmail.com
AuthPass=Hunter2
FromLineOverride=yes

(have also tried without root line, and with rewriteDomain=gmail.com)

.fetchmailrc file, same as above except mda line is now:

mda "/opt/local/sbin/ssmtp FIXME@gmail.com"
  • I guess I meant that gmail itself (i.e. go to gmail.com settings and forwarding imap/pop) you can only fetch from POP accounts. So in terms of having gmail do the fetching. Are you having mutt do the fetching from an imap account and then sending to gmail? If you are doing it via mutt is that not too dissimilar to the workarounds above? I'm not familiar with mutt, if you are able to share config could see if it would work though maybe we are not quite talking about the same thing. – Amanda Jun 9 '17 at 16:56
  • Maybe point out how this isn't a duplicate of your previous question unix.stackexchange.com/questions/369842/… – tripleee Jun 10 '17 at 6:08
  • 1
    I understand that gmail will always rewrite the From: header to your login, eg question on serverfault. Perhaps you should setup your forwarder as a POP3 server and get gmail to read from it (means opening a port, security implications). Or, more complex, package each mail as an embedded mail, send it, and at the other end open up the pristine embedded mail. – meuh Jun 10 '17 at 18:39
  • @tripleee Is it proper etiquette to point this out in a comment or in the main question text? – Amanda Jun 12 '17 at 13:39
  • @meuh Huh, ok so there may be no "easy" around this using the methods I am currently setting up? When others online have indicated that have been able to use similar set ups to forward email is no one else trying to also be able to respond directly to this email (that question was not sarcastic but serious) – Amanda Jun 12 '17 at 13:40
0

If your configuration allows it, Sendmail (and presumably also the sendmail program from ssmtp) lets you override the envelope sender with -f.

Here's a quick whack at doing it from Procmail.

:0
* ^Return-Path:[    ]*\/[^  ].+
! -f "$MATCH" myusername@gmail.com

The whitespace inside the square brackets should be a space and a tab, in any order. (Copy/paste from above might not work correctly from your browser.)

The \/ special token causes Procmail to capture the matching text behind it after the token into the variable MATCH. We use this to copy the value from the Return-Path: header and pass that as the argument to the -f option.

This presupposes that the original envelope sender is correctly annotated in the Return-Path: header; modern MTAs should do this across the board, but if your upstream is Microsoft, unpleasant surprises should be expected.

You also need to understand the purpose of the envelope sender. This will cause any bounces to go to the original sender, for example. The proper solution to this problem is to transport the messages to the final destination, instead of redeliver them.

... Or configure Gmail to display a different "sender" than its default, and reply to that instead.

(I imagine you are asking about the envelope sender, since the sender headers of the forwarded message should generally be preserved when you forward a message, though some MTAs will also add a Sender: header when the From: header's value or the envelope sender has been overridden. Perhaps update your question to indicate what headers exactly end up with the wrong value if this is not it.)

  • Thanks @tripleee, I tried your code and get the same issue. Let me try my best to clarify, but I actually think it may not be the envelope sender causing the issue but I'm not 100% sure. – Amanda Jun 12 '17 at 12:56
  • Sorry I hit enter too soon on above: Thanks @tripleee, I tried your code and get the same issue. Let me try my best to clarify, but I think it may not be the envelope sender causing the issue but I'm not 100% sure. If you tripleee@domain.net send an email to me, amanda@work.com, it gets forwarded ok to amanda@gmail.com. HOWEVER, in gmail the From: says "Tripleee <amanda@gmail.com> - rather than Tripleee <triplee@domain.net> - and if I reply from gmail the reply weirdly goes to the first person cc'd in the "To: " portion of the email, rather than the sender. Was that clarifying at all? – Amanda Jun 12 '17 at 13:05
  • To clarify, that was after trying your procmail config. However, I believe the behavior was similar with my .procmailrc config – Amanda Jun 12 '17 at 13:08
  • Looks like meuh's cross-site duplicate is spot on, and that there's really nothing you can do on the forwarding side to fix that. – tripleee Jun 13 '17 at 8:38
  • I'll leave this answer here on the odd chance that it'll help someone who is actually struggling with the envelope sender. This is not the OP's problem, though. – tripleee Jun 13 '17 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.