+1 vote

I am testing the software (implicating I am a newbie with this software) and I follow the example coding to forward an email.

While sending I get a System.ArgumentException in Mail.dll and the msg that the From address is empty.

With the Visual Studio debugger I see the From is set and the trace shows me a good smtp connection.

Can it be that there is a kind of validation check clearing the From adress?

The coding:

// MailConfig is my class to insert the userid and passwords

ForwardBuilder forwardBuilder = email.Forward();
email.To.Clear();
email.From.Clear();
email.To.Add(new MailBox(MailConfig.erroradress));
email.From.Add(new MailBox("valid emailname", "name"));
Log.Enabled = true;
using (Smtp smtp = new Smtp())
{
    smtp.Connect(MailConfig.smtpserver); 
    MailConfig.Connect(MailConfig.smtpuser, smtp); // here it goes wrong

    ISendMessageResult result = smtp.SendMessage(email);
by (250 points)

1 Answer

0 votes

IMail.Forward() method creates and returns new ForwardBuilder configured to forward this email.

You can use it to overwrite default subject and body templates, and in the end to create a MailBuilder instance.

MailBuilder is used to create the final email. You can use it to modify the email in any way you want (same as you would create a new mail message).

Your code should look like this.

ForwardBuilder forwardBuilder = email.Forward();

// You can set custom templates on forwardBuilder:
//forwardBuilder.SubjectReplyTemplate = "Fwd: [Original.Subject]";

MailBuilder builder = forwardBuilder.Forward(new MailBox("valid emailname", "name"));

// You can modify how the final email look like here:
//builder.AddAttachment("c:\\report.txt");
//builder.Subject = "overwrite the subject";

IMail forwarded = builder.Create();

using (Smtp smtp = new Smtp())
{
    smtp.Connect(MailConfig.smtpserver);
    MailConfig.Connect(MailConfig.smtpuser, smtp); 

    ISendMessageResult result = smtp.SendMessage(forwarded);
}
by (301k points)
...