+1 vote

I sent a mail to my gmail account e.g abc@gmail.com from my yahoo account abc@yahoo.com. No i want to reply from abc@gmail.com back to abc@yaoo.com

I fetched the original mail from my gmail account abc@gmail.com using its UID so i can build a reply mail. It was successfully fetched with the FROM property set to abc@yahoo.com and the TO property set to abc@gmail.com as expected. code is a below:

IMail original = Getuidmessage(getimapset.imap, getimapset.port, 
    getimapset.username, getimapset.password, 
    theuidtofetch, nassl);

ReplyBuilder replyBuilder = original.Reply();

// You can specify your own, custom, body and subject templates:
replyBuilder.HtmlReplyTemplate = @"
    <html>
    <head>
        <title>[Subject]</title>
    </head>
    <body>
        [Html]
        <br /><br />
        On [Original.Date] [Original.Sender.Name] wrote:
        <blockquote>
            [QuoteHtml]
        </blockquote>
    </body>
    </html>";
replyBuilder.SubjectReplyTemplate = "Re: [Original.Subject]";

replyBuilder.Html = additional_message + message1.ToString();

MailBuilder thebuilder = replyBuilder.Reply(
    new MailBox(original.Sender.Address, original.Sender.Name));
thebuilder.ReplyTo.Add(new MailBox(getimapset.username, sender_fullname));
thebuilder.ReturnReceiptTo.Add(
    new MailBox(getimapset.username, sender_fullname));
thebuilder.RequestReadReceipt();

IMail reply = thebuilder.Create();

1st Problem:

IMail reply = thebuilder.Create();

While inspecting the reply IMail variable, the FROM property is set to abc@yahoo.com and the TO property is set to abc@yahoo.com. My expected FROM property should be abc@gmail.com while the TO property to abc@yahoo.com. When the mail finally delivers, it displays as a mail from ME to ME which is hilariously wrong for me.

2nd problem
when i use to ReplyToAll() method to create my builder as below

MailBuilder thebuilder = replyBuilder.ReplyToAll(
    new MailBox(original.Sender.Address, original.Sender.Name));

It sets my FROM property to abc@yahoo.com and the TO property to abc@gmail.com.I expect the reverse.

I dont know if this is a bug but its not working for

Note: I am using the SMTP of abc@gmail.com as the reply person.

by (551 points)

1 Answer

0 votes
 
Best answer

The problem is in this line:

MailBuilder thebuilder = replyBuilder.Reply(
    new MailBox(original.Sender.Address, original.Sender.Name));

it effectively is:

MailBuilder thebuilder = replyBuilder.Reply("abc@yahoo.com");

ReplyBuilder.Reply takes a single parameter "from". It specifies the From mailbox used for replying.

You should be specifying from which account you are replying (as there might be many to's in the original email). In other words you specify who is replying.

This is the code that works:

MailBuilder thebuilder = replyBuilder.Reply("abc@gmail.com");

and an unit test, to easily reproduce this situation:

MailBuilder originalBuilder = new MailBuilder();
originalBuilder.From.Add(new MailBox("abc@yahoo.com"));
originalBuilder.To.Add(new MailBox("abc@gmail.com"));
IMail original = originalBuilder.Create();

MailBuilder thebuilder = original.Reply().Reply("abc@gmail.com");

IMail reply = thebuilder.Create();

Assert.AreEqual("abc@gmail.com", reply.From[0].Address);
Assert.AreEqual("abc@yahoo.com", ((MailBox)reply.To[0]).Address);
by (297k points)
selected by
So you mean to say the email argument in replyBuilder.Reply("email string") should be the email address of the sender i.e replier. In my case - (abc@gmail.com)?
Exactly. It's the address of the replier.
I think you need to make this very clear on the documentation, intellisence and sample code. It will save alot of lives.Thanks alot!!!. lol
Will try to make that more obvious.
...