Forward Emails preserving recipients (INDY and Delphi) - email

I retrieve eMails from a GMail account with a TIdIMAP4-object and want to forward them with TIdSMTP to an other (GMail-)account while preserving the original list of recipients.
My approach was adding the destination address as BCC to make it invisible in the destination, but how can I prevent the SMTP component from sending it to all the other recipients in the list? They then would get all the forwarded mails twice.
UPDATE 1:
Instead of using BCC I provided the destination address in the send statement
smtp.Send(msg,destination);
but the message is still sent to all the other recipients.

By default, TIdSMTP.Send() will send the email to all of the recipients listed in the Recipients, CcList and BccList properties of TIdMessage.
When you download an email into a TIdMessage via POP3 or IMAP, the Recipients and CcList (but not the BccList) are filled in from the email's existing To and CC headers, respectively.
When you then forward the email, if you do not want it to be sent to the recipients specified in the email, then you can call the overloaded version of TIdSMTP.Send() that takes a recipient list as a parameter. That will send the email ONLY to that list. For example:
var
forwardTo: TIdEmailAddressList;
begin
...
forwardTo := TIdEmailAddressList.Create;
try
// add desired recipients to forwardTo as needed, then...
smtp.Send(msg, forwardTo);
finally
forwardTo.Free;
end;
...
end;

Related

How to change recipient of a VACATION autoresponder mail to one in sender's mail header section [Reply-to] purely in Sieve Language?

I need to set an autoresponder that will send a message like "We got You mail! We will get back to you ASAP". The problem is that the sender of customer email is not customer itself (i.e. customer#privatemail.com), but some global mail (i.e. customerservice#marketplace.com) that contains customer private mail in the header section [Reply-to].
This is a hosted server with installed RoundCube. I can only use Sieve filters to create an autoresponder.
rule:[Autoresponder]
if allof (
header :contains "from" "#marketplace.pl",
{
vacation text:
We got You mail! We will get back to you ASAP!
.
;
}
I need to read the value of the header [Reply-To] section, set the recipient of autoresponder mail to that value and send a VACATION message. Only in Sieve language.

Which SMTP code must the server return when the Email could not be delivered to all recipients?

Which SMTP code must the server return when the Email could not be delivered to all recipients?
I mean the case when there are multiple recipient.
Let's say there are RCPT A, RCPT B, RCPT C and the end of the DATA the server can deliver to A and B, but not to C.
As a server, I must not response with code 250. Right? Then which code must I response with?
And the other hand, I neither can give them code 5xx, because they may double the Email for A and B.
In typical implementation/scenario:
server refuses to accept "obviously" invalid recipients in reply to RCPT TO:
(e.g. non existing DNS domain or non existing user/mailbox in local email domain)
accepts message in reply to the final dot (or rejects it as spam)
tries to send accepted message to recipients
sends back "bounce messages" to envelope sender (MAIL FROM:) after repeated/multiple delivery attempts fail

MailKit: How to get the To email address when it is an alias

I am sending an email to alias#company.com which is an alias to a real mailbox address. I then connect to the real mailbox (let's say realmailbox#company.com) using MailKit and retrieve messages. When I inspect the To address, all I see is the realmailbox#company.com. How to I see the original alias address that the email was sent to?
For example:
var fullMessage = imapClient.Inbox.GetMessage(uid);
var recipients = fullMessage.To;
recipients only show the realmailbox#company.com, not the alias#company.com.
It sounds to me like your SMTP server is performing a string substitution on the alias before passing it along to the recipient mailbox making it impossible to get the info you are looking for.

Sending EMails with Indy with multiple CCs. If one is incorrect nobody recieves the mail

I currently setting up a little tool for my company that is used to send info-mails to specific user groups.
But if one or more email addresses are incorrect (missing letter etc.) I get following error and the email isn't sent at all:
EIdSMTPReplyError
Requested action not taken: mailbox unavailable
invalid DNS MX or A/AAAA resource record
I set up the email like this:
adding the first email as main recipient
adding all others to the cclist
Is there a way to set up the email so atleast the other recipients are getting the email?
Some Infos:
Delphi 7
Indy 10
Thanks in advance <3
TIdSMTP has an OnFailedRecipient event:
type
TIdSMTPFailedRecipient = procedure(Sender: TObject; const AAddress, ACode, AText: String;
var VContinue: Boolean) of object;
AAddress is the email address, and ACode and AText contain the error details.
If VContinue is set to True (the default when OnFailedRecipient is assigned), the failed email is skipped and the next recipient is attempted.
The EIdSMTPReplyError exception is raised if either:
OnFailedRecipient is not assigned when a recipient fails.
VContinue is set to False.
all recipients fail, regardless of OnFailedRecipient.

Send email to address alternate from "To:"

I am implementing a sort of dynamic mailing-list system in Rails. I am looking to basically send an email and have the recipient receive it in this form:
From: person#whosentthis.com
To: mailing-list#mysite.com
<body>
Basically, the challenge is how do I send an email to an address while defining a different To: header so that they can easily reply to the mailing list or just the original sender?
Mail vs. Envelope
In emails as in physical mails (paper sheet in paper envelope), the recipient on the envelope may differ from the recipient on the letter sheet itself.
As the mailman would only consider the envelope's recipient, so do mail servers.
That means, one actually can tell the smtp service to send and email to a recipient different than the one listed in the To: field of the emails header.
Trying This Out Manually
You can try this out, manually, for example, by using the sendmail command of postfix.
# bash
sendmail really_send_to_this_address#example.com < mail.txt
where
# mail.txt
From: foo#example.com
To: this_will_be_seen_in_the_to_field_in_email_clients#example.com
Subject: Testmail
This is a test mail.
This will deliver the email to really_send_to_this_address#example.com, not to this_will_be_seen_in_the_to_field_in_email_clients#example.com, but the latter will be shown in the recipient field of the mail client.
Specifying the Envelope_to Field in Rails
The ActionMailer::Base internally uses the mail gem. Currently, Apr 2013, there is a pull request, allowing to specify the envelope_to field on a message before delivery.
Until this is pulled, you can specify the fork in the Gemfile.
# Gemfile
# ...
gem 'mail', git: 'git://github.com/jeremy/mail.git'
You need to run bundle update mail after that, and, depending on your current rails version, maybe also bundle update rails in order to resolve some dependency issues.
After that, you can set the envelope recipient of a mail message like this:
# rails
message # => <Mail::Message ...>
message.to = [ "this_will_be_seen_in_the_to_field_in_email_clients#example.com" ]
message.smtp_envelope_to = [ "really_send_to_this_address#example.com" ]
message.from = ...
message.subject = ...
message.body = ...
message.deliver
Documentation
https://github.com/mikel/mail/pull/477
http://rubydoc.info/github/jeremy/mail/master/Mail/Message#smtp_envelope_to%3D-instance_method
https://github.com/mikel/mail
Why not use the BCC header for this? Put person#whoshouldreceivethis.com into BCC and mailing-list#mysite.com into TO.
Clearification:
There is no technical solution for this. The email headers do what they do, you can't influence them in that once the email is on the way.
I am sure, though, you can find a combined use of TO, CC, BCC and REPLY-TO that gives you what you want.