Forward Mail

Jul 23, 2012 at 11:29 AM
Edited Jul 23, 2012 at 12:22 PM

Hi,

I simply want to forward a mail I've got with pop or imap (after modifying the text a little bit, for a newsletter). Why is it that SmptClient.SendMail expects a SmtpMessage and not simply a MailMessage or the common base class InternetTextMessage?

This seems like not so good library design, and I've seen this already with other commercial libraries. There shouldn't be different classes for the same thing, or at least a way to convert from each other.

 

Greetings,

 

Simon Egli

Coordinator
Jul 23, 2012 at 12:29 PM

You can easily convert by using CreateSmtpMessage method of MailMessage object.

I think these two class are not same.
MailMessage is parsed from text (RFC822), SmtpMessage create text data to send.
If MailMessage and SmtpMessage are same, for example how do you design it.
------------------------------------------------------------------
String mailText = "mail text....";
MailMessage mg = new MailMessage(mailText);
String text = mg.GetDataText();
bool bl = mailText == text;
------------------------------------------------------------------
Developer expect bl is true but it may be difficult to implement.
That is one example.
If I implement these Smtp,parse functionality only one class, that reduce intuitive usability because the class has too much method and property.
Developer may want to send mail or receive mail.
There are no use case to send and receive at the same time.
So I create two class for these two use case, and I keep API more intuitive.

And I simply provide CreateSmtpMessage method.
The requirement to forward mail can be solved very easily by using this method.
And my design does not cause any problem on class api design.


It is easy to say, but difficult to do.
If you have any idea, please show me actual source code how to achieve it.
That may improve library and help developer who use this library.



regards

Aug 3, 2012 at 3:42 PM
Hi,
Thanx for your reply. I wasn’t aware of the CreateSmtpMessage method, so this solves my problem.
Thanx,
Simon Egli
From: [email removed]
Sent: Monday, July 23, 2012 8:30 PM
To: [email removed]
Subject: Re: Forward Mail [higlabo:387513]

From: higty

You can easily convert by using CreateSmtpMessage method of MailMessage object.

I think these two class are not same.
MailMessage is parsed from text (RFC822), SmtpMessage create text data to send.
If MailMessage and SmtpMessage are same, for example how do you design it.
------------------------------------------------------------------
String mailText = "mail text....";
MailMessage mg = new MailMessage(mailText);
String text = mg.GetDataText();
bool bl = mailText == text;
------------------------------------------------------------------
Developer expect bl is true but it may be difficult to implement.
That is one example.
If I implement these Smtp,parse functionality only one class, that reduce intuitive usability because the class has too much method and property.
Developer may want to send mail or receive mail.
There are no use case to send and receive at the same time.
So I create two class for these two use case, and I keep API more intuitive.

And I simply provide CreateSmtpMessage method.
The requirement to forward mail can be solved very easily by using this method.
And my design does not cause any problem on class api design.


It is easy to say, but difficult to do.
If you have any idea, please show me actual source code how to achieve it.
That may improve library and help developer who use this library.



regards

Aug 7, 2012 at 2:33 PM
Hi higty,
CreateSmpMessage does not work. It does not send embedded images, but instead sends the whole mail as text, also the embedded stuff.
Is it possible that you fix this in the near future?
I’ll send you the original email, and the fowarded email separately.
My code looks as follows, it is for sending a newsletter that was received on a mail account:
public static void Pop() {
using (var mailbox = new ImapClient(Configuration.Server, Configuration.Port, Configuration.Username, Configuration.Password)) { // copy all incoming mail to Review
mailbox.Open();
mailbox.Ssl = false;
mailbox.Authenticate();
var inbox = mailbox.SelectFolder("INBOX");
try {
mailbox.ExecuteCreate("Review");
} catch { }
mailbox.ExecuteCopy(1, inbox.MailCount, "Review");
mailbox.Close();
}
using (var mailbox = new ImapClient(Configuration.Server, Configuration.Port, Configuration.Username, Configuration.Password)) { // read all incoming mail and prepare for newsletter and send preview
mailbox.Open();
mailbox.Ssl = false;
mailbox.Authenticate();
var inbox = mailbox.SelectFolder("INBOX");
for (var i = 0; i < inbox.MailCount; i++) {
var index = i + 1;
MailMessage msg = mailbox.GetMessage(index);
mailbox.DeleteEMail(index);
var smtpMsg = msg.CreateSmtpMessage();
var text = smtpMsg.BodyText;
text = text.Replace("#andrede", "Sehr geehrter Herr")
.Replace("#name", "Max")
.Replace("#vorname", "Muster")
smtpMsg.To.Clear();
smtpMsg.To.Add(new MailAddress(msg.From));
smtpMsg.From = msg.From;
smtpMsg.Subject = msg.Subject;
using (var smtp = new SmtpClient(Mail.Configuration.SmtpServer, Mail.Configuration.SmtpPort, Mail.Configuration.SmtpUsername, Mail.Configuration.SmtpPassword)) {
smtp.SendMail(smtpMsg);
}
var mail = Mail.FromTemplate("~/emails/confirmnewsletter.aspx"); // send mail with a link to actually send out the newsletter
mail.ToEmail = msg.From;
mail.From = new System.Net.Mail.MailAddress("info@homesell.ch");
var review = mailbox.SelectFolder("Review");
mail["#mailno"] = review.MailCount.ToString();
mail.Send();
Silversite.Services.Log.Write("Newsletter", "Newsletter ready for review.");
}
}
From: [email removed]
Sent: Monday, July 23, 2012 8:30 PM
To: [email removed]
Subject: Re: Forward Mail [higlabo:387513]

From: higty

You can easily convert by using CreateSmtpMessage method of MailMessage object.

I think these two class are not same.
MailMessage is parsed from text (RFC822), SmtpMessage create text data to send.
If MailMessage and SmtpMessage are same, for example how do you design it.
------------------------------------------------------------------
String mailText = "mail text....";
MailMessage mg = new MailMessage(mailText);
String text = mg.GetDataText();
bool bl = mailText == text;
------------------------------------------------------------------
Developer expect bl is true but it may be difficult to implement.
That is one example.
If I implement these Smtp,parse functionality only one class, that reduce intuitive usability because the class has too much method and property.
Developer may want to send mail or receive mail.
There are no use case to send and receive at the same time.
So I create two class for these two use case, and I keep API more intuitive.

And I simply provide CreateSmtpMessage method.
The requirement to forward mail can be solved very easily by using this method.
And my design does not cause any problem on class api design.


It is easy to say, but difficult to do.
If you have any idea, please show me actual source code how to achieve it.
That may improve library and help developer who use this library.



regards

Coordinator
Aug 16, 2012 at 5:40 AM

Thank you for your detail report.
I'll investigate your report.
If there is a bug, I'll fix it at least one or two week.


regards.

Coordinator
Aug 16, 2012 at 7:32 AM

I fixed bug rapidly.
And upload new version that work with attachment.
Please check it out.