Sending email using .NET System.Web.Mail

HeatEx

Guppy
Hi all. I need to customize my email sending, so I can't use the standard lists. I track the emails I need to send to in a database and use System.Web.Mail.MailMessage class from an aspx page on my site to send them.

It works fine just using the local Smtp server, except I get blocked by all the big people (hotmail, gmail, yahoo, etc). Is there a way I can use my actual relay server to send the mails, instead of just the local smtp server on the web server?

I tried setting the SmtServer for SmtpMail to my relay (see C# code below), but then all mails fail since I don't have access to send from the relay server. Is there a way to make this work?

Thanks,
Keith

Code:

MailMessage msg = new MailMessage();
msg.From = fromEmail
msg.Subject = subject;
msg.To = toEmail;
msg.Body = body;
msg.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = "mail2.jodoshared.com";
SmtpMail.Send(msg);
 
Ugh.... I just needed to post to finally figure it out I guess...

For those reading this with the same problem, you use the realy server (or your own mail.MyDomain.com) and then you authenticate against the Smtp server using MailMessage fields:

So add this stuff in my code above:

msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = relayServer;
msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
msg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sendEmail; msg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = password;

SmtpMail.SmtpServer = relayServer;

Here's where I found it:
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=622
 
Thanks for that. I didn't realise that could be done with .NET 1.1 although now that I know what to look for, I see that its even in the .NET docs as an example for the MailMessage.Fields property.

FYI, .NET 2.0 has a new namespace, System.Net.Mail, for sending email with lots of functionality, including the authentication.

Cheers
Ross
 
Yeah, forgot to mention this was 1.1, thanks for pointing that out. I'll be going to 2.0 soon hopefully...
 
Back
Top