Forwarding a MSG file as New mail Message

I am trying to forward a MSG file to new mail message but it does not work (.NET 4.0). It will save it to a new msg file, I can read properties. But it send send method does nothing:

try
{
//Instantiate an instance of license and set the license file through its path
Aspose.Email.License license = new Aspose.Email.License();
license.SetLicense(“Aspose.Email.lic”);

// create an instance of MailMessage
MailMessage msg = new MailMessage();
msg = MailMessage.Load(“C:\TestMail.msg”, MessageFormat.Msg);

// load the MIME message from a local disk file
msg.Subject = "FW: " + msg.Subject;
Console.WriteLine("Subject: "+ msg.Subject);

msg.To = MyEmailAddress;
msg.Save(“c:\message2.msg”, MessageFormat.Msg); // This works

msg.From = MyEmailAddress;

//sent Mail using SmtpClient
//Create an instance of SmtpClient Class

//declare test message as MailMessage instance
MailMessage message = new MailMessage();

[//txtFrom.Text](https://txtfrom.text/) is the sender’s address
message.From = MyEmailAddress;
[//txtTo.Text](https://txtto.text/) is the recipient’s address
message.To = MyEmailAddress;
message.Subject = “My First Mail”;
message.TextBody = “This is a Apsose Test”;

SmtpClient client = new SmtpClient();

//Specify your mailing host server
client.Host = MyRelay;
//Specify your Port #
client.Port = 25;

[//Client.Send](https://client.send/) will send this message
client.Send(msg); //This does not work???
client.Send(message); // This Works!!!

}
catch (Exception x)
{
// Show exception message
Console.WriteLine(“Error occured: {0}”, x.Message);
}

Hi,


Thank you for your inquiry.

Can you please share the message file that you are loading from disk and trying to send via SmtpClient.

Regards,

Hi again,

I am afraid, I am unable to replicate your said issue with Aspose.Email for .NET v1.2.0 1 Framework 4.0 assembly. Below is my sample code for your reference.

C#

Aspose.Email.Mail.MailMessage msg = Aspose.Email.Mail.MailMessage.Load(“message.msg”,Aspose.Email.Mail.MessageFormat.Msg);
Aspose.Email.Mail.MailAddressCollection addresses = msg.To;
addresses.RemoveAt(0);
addresses.Add(new Aspose.Email.Mail.MailAddress("myAccount@domain.com"));

Aspose.Email.Mail.SmtpClient client;
client = new Aspose.Email.Mail.SmtpClient(“smtp.gmail.com”, 587, "username@gmail.com", “password”);
client.DeliveryMethod = Aspose.Email.Mail.SmtpDeliveryMethod.Network;
client.AuthenticationMethod = Aspose.Email.Mail.SmtpAuthentication.None;
client.SecurityMode = Aspose.Email.Mail.SmtpSslSecurityMode.Explicit;
client.EnableSsl = true;
client.Send(msg);

I found the problem. It was the contents of the header related to routing of the message. I reworked the code to look like the following:

string DateSent;
string FromAddress;
string ToAddress;
string CCAddress;
string Subject;
string BodyHeader;

//Instantiate an instance of license and set the license file through its path

// create an instance of MailMessage
MailMessage msg = new MailMessage();
msg = MailMessage.Load(“C:\TestMail2.msg”, MessageFormat.Msg);

FromAddress = msg.From.ToString();
ToAddress = msg.To.ToString();
CCAddress = msg.CC.ToString();
DateSent = msg.Date.ToString();
Subject = msg.Subject;

BodyHeader = “
” + “----------------------------------------------” + “
”;
BodyHeader = BodyHeader + "From: " + FromAddress + “
”;
BodyHeader = BodyHeader + "Sent: " + DateSent + “
”;
BodyHeader = BodyHeader + "To: " + ToAddress + “
”;
BodyHeader = BodyHeader + "CC: " + CCAddress + “
”;
BodyHeader = BodyHeader + "Subject: " + Subject + “
”;

msg.Body = BodyHeader + msg.Body;
msg.Headers.Clear(); // This is the trick need for existing messages
msg.Subject = Subject;
msg.To = MyEmailAddress;
msg.Save(“c:\message2.msg”, MessageFormat.Msg); // This works
msg.From = MyEmailAddress;

Hi,


We are glad that your issue is resolved and thank you for posting your solution.

In case you have further queries or comments, please feel free to write back.

Regards,