1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| private void SendMessage1(string mailfrom, string mailto, string password, string host, string subject, string body)
{
try
{
CDO.Message message = new CDO.Message();
CDO.IConfiguration configuration = message.Configuration;
ADODB.Fields fields = configuration.Fields;
ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
field.Value = host;
field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
field.Value = 465;
field = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
field.Value = CDO.CdoSendUsing.cdoSendUsingPort;
field = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
field.Value = CDO.CdoProtocolsAuthentication.cdoBasic;
field = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
field.Value = mailfrom;
field = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
field.Value = password;
field = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
field.Value = true;
fields.Update();
message.From = mailfrom;
message.To = mailto;
message.Subject = subject;
message.TextBody = body;
message.Send();
}
catch (Exception ex)
{
ErrorMessage = ex.Message;
}
} |