views:

756

answers:

2

Hey everyone,

What I am trying to do is pass the raw content of an outgoing email to spamassassin in order to calculate a spam score. I am stuck in how I might get the raw content of the email.

My C# code currently just constructs the MailMessage and passes it the SmtpClient's Send() method. Before sending, is there a way to get a raw version of the mail message (as the protocol might see it) so that I can pass this to the spamassassin tool for spam assessment?

If I've not explained very well, let me know and I'll try to explain better.

Thanks in advance,

Martin.

+2  A: 

I've worked out a solution to my problem.

The SmtpClient class has two properties that can be set which cause the email to be stored to an EML file rather than actually sent. The original purpose of this is so that the email could be generated with SmtpClient but actually picked up and sent by another SMTP server.

SmtpClient.DeliveryMethod
SmtpClient.PickupDirectoryLocation

If the SmtpClient.DeliveryMethod is set to SmtpDeliveryMethod.SpecifiedPickupDirectory and the SmtpClient.PickupDirectoryLocation is set to the full path of some directory on the machine, then calling SmtpClient.Send(mailMessage); causes it to be saved.

In turn, the newly created EML file can be passed to spamassassin directly on the command line in order to get the spam score I needed.

Hope this info helps anyone else with this issue.

Kind regards,

Martin.

Martin
A: 

Yes, your answer is very useful.

It's insane that MailMessage does have a viable toString() or GetMessage() method so that you can see the full message, as it will be sent, prior to sending it.

Without a proper debug facility, you could very easily get into trouble with destination mailservers, who could log your test message as spam and blacklist your server, just because of a formatting or field content issue, such as security and other information fields.

And the smtp object doesn't help either.

This is more than an oversight on the part of Microsoft in the C# object, it's completely pompous, sophomoric, and irresponsible.

Thanks for helping the programming community.

John