views:

194

answers:

3

I previously used CDO.Message and CDO.Configuration in ASP Classic to create HTML emails which was VERY simple to do. In .NET, it appears that you have to give the System.Net.Mail.Message object an HTML string for the content and then somehow embed the required images. Is there an easy way to do this in .NET? I'm pretty new to .NET MVC and would most appreciate any help.

This is how it looks in ASP Classic:

Set objCDO = Server.CreateObject("CDO.Message")
objCDO.To = [email protected]
objCDO.From = [email protected]
objCDO.CreateMHTMLBody "http://www.mysite.com/somepage.html"
objCDO.Subject = sSubject

'the following are for advanced CDO schematics
'for authentication and external SMTP

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields  
  .Item(cdoSendUsingMethod) = cdoSendUsingPort '2 - send using port  
  .Item(cdoSMTPServer) = mail.myaddress.com
  .Item(cdoSMTPServerPort) = 25
  .Item(cdoSMTPConnectionTimeout) = 10
  .Item(cdoSMTPAuthenticate) = cdoBasic
  .Item(cdoSendUsername) = "myusername"
  .Item(cdoSendPassword) = "mypassword"
  .Update  
End With

Set objCDO.Configuration = cdoConfig

objCDO.Send

Basically I would like to send one of my views (minus site.master) as an email, images embedded.

A: 

Here's a detailed tutorial

John Sheehan
A: 

I don't know of a simple way right off, but you could use WebClient to get your page, then pass the response as the body.

Example:

var webClient = new WebClient();

byte[] returnFromPost = webClient.UploadValues(Url, Inputs);

var utf = new UTF8Encoding();
string returnValue = utf.GetString(returnFromPost);

return returnValue;

Note: Inputs is just a dictionary of post variables.

One problem I think you'll run into right off is that I don't think you'd get the images. You could parse the HTML you get and then make the images absolute back to your server.

CubanX
A: 

Thank you both for your help - here is a very clean and comprehensive tutorial posted by a .NET MVP http://msdn.microsoft.com/en-us/vbasic/bb630227.aspx