private void SendMail2(str _FileName,Str60 _Subject,Notes _Body)
{
str Toaddress;
System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress fromMail;
System.Net.Mail.MailAddressCollection toadrr;
System.Net.Mail.SmtpClient smCL = new System.Net.Mail.SmtpClient();
System.Net.NetworkCredential credential;
str bodygrd,sSmtpServer;
CLRObject exc;
CLRObject innerExc;
CLRObject clrExcMessage;
str strError;
SysEmailParameters EmailParm;
str pass;
System.Net.Mail.AttachmentCollection mailAttachementCollection;
System.Net.Mail.Attachment mailAttachment;
;
toaddress="test@hotmail.com";
EmailParm = SysEmailParameters::find();
pass = SysEmailParameters::password();
credential = new System.Net.NetworkCredential(EmailParm.SMTPUserName,pass);
fromMail = new System.Net.Mail.MailAddress(EmailParm.SMTPUserName);
new InteropPermission(InteropKind::ClrInterop).assert();
try
{
Msg.set_From(fromMail);
toadrr = Msg.get_To();
toadrr.Add(new System.Net.Mail.MailAddress(toaddress));
Msg.set_Subject(_Subject);
Msg.set_Body(_body);
Msg.set_IsBodyHtml(true);
sSmtpServer = EmailParm.SMTPRelayServerName;
smCL.set_Host(sSmtpServer);
mailAttachementCollection = msg.get_Attachments();
mailAttachment = new System.Net.Mail.Attachment(_fileName);
mailAttachementCollection.Add(mailAttachment);
smCL.set_Port(EmailParm.SMTPPortNumber);
smCL.set_EnableSsl(true);
smCL.set_Credentials(credential);
smCL.Send(Msg);
} catch( Exception::CLRError )
{
exc = CLRInterop::getLastException();
if( exc )
{
clrExcMessage = exc.get_Message();
innerExc = exc.get_InnerException();
while(innerExc != null)
{
clrExcMessage = innerExc.get_Message();
innerExc = innerExc.get_InnerException();
}
strError = CLRInterop::getAnyTypeForObject( clrExcMessage );
throw error(strError);
}
}
}
Hiç yorum yok:
Yorum Gönder