HTML Email

  • Thread starter Thread starter Andrew Robinson
  • Start date Start date
A

Andrew Robinson

I used to use CDO to send HTML embedded emails (including images). I can't
seem to get this working using COM Interop. System.Web.Main doesn't seem
allow for embedded graphics. Any ideas? I would really like to role my own
rather than purchasing a 3rd party library.

Tageting a windows forms application in c#. Have attached the old VB6 code
as an example.

thanks,


Private Sub sendMessage(messageTo As String, messageFrom As String,
messageSubject As String, messageBody As String, errorInfo As String,
ClientID As Long)
Dim iMsg As New cdo.Message
Dim iConf As New cdo.Configuration
Dim Flds As ADODB.Fields
Set Flds = iConf.Fields

Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "localhost"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPConnectionTimeout) = 30
Flds(cdoSendUserReplyEmailAddress) = txtFrom
Flds(cdoSendEmailAddress) = txtFrom
Flds.Update

Set iMsg.Configuration = iConf

iMsg.To = messageTo
iMsg.subject = messageSubject
iMsg.AutoGenerateTextBody = True
iMsg.TextBody = messageBody
iMsg.CreateMHTMLBody txtHTMLurl, cdoSuppressNone
iMsg.Send
 
Hi Andrew,

Create an interop assembly for the CDO library used by the VB6 code,
reference it from your C# project and then just port the VB code to C#.
P.S. You will have to create an interop assembly for ADODB as well.
 
Hi Dmitriy,

No sure whether the problem is something incorrect when you interop call
your vb6 COM dll.
Can you correctly use CDO component directly to send mail in .net
application through COM interop? From my local test , I can successfully
use CDO to send html mails with embeded images in a winform app. Here is
the test code:

=========================
private void btnSendCDO_Click(object sender, System.EventArgs e)
{
try
{
CDO.Message msg = new CDO.MessageClass();

msg.To = txtEmail.Text;

msg.Subject = "Test Image Mail";
msg.From = "(e-mail address removed)";

msg.CreateMHTMLBody("http://www.asp.net",CDO.CdoMHTMLFlags.cdoSuppressNone,"
","");

CDO.Configuration config = new CDO.ConfigurationClass();

ADODB.Fields fields = null;

fields = config.Fields;

ADODB.Field field = null;

field =
fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
field.Value = 1;

field =
fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
field.Value = CDO.CdoPostUsing.cdoPostUsingPort;

field =
fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
field .Value = "smtphost";


fields.Update();
msg.Configuration = config;
msg.Send();


msg = null;
config = null;
fields = null;
field = null;

}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}

}
=====================================

HTH.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top