Catatan: mailTo hanya bisa diisi 1 email, bila lebih, maka hanya email yg pertama saja yg diproses.
void Send_Emailx(str subjectx,str bodyx,str sendtomailx,str sendtonamex)
{
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.SmtpClient myMail;
System.Net.Mail.MailAddressCollection mailcoll;
System.Net.Mail.MailAddress mailFrom;
System.Net.Mail.MailAddress mailTo,mailTo2;
System.Net.Mail.MailAddress mailCC;
str receiverMailAddress;
str mailBody;
str smtpServer;
str mailSubject;
str CcMailAddress;
int SMTPPort;
#File
str mail,companynamex;
userinfo userInfo;
str pwd;
SysEmailParameters parameters = SysEmailParameters::find();
;
new InteropPermission(InteropKind::ClrInterop).assert();
mailSubject = subjectx;
companynamex = companyinfo::find().Name;
mailFrom = new System.Net.Mail.MailAddress(parameters.SMTPUserName , "AX Server "+companynamex);
mailTo = new System.Net.Mail.MailAddress(sendtomailx,sendtonamex);
mailCC = new System.Net.Mail.MailAddress('mail@gmail.com','mail');
mailcoll = new System.Net.Mail.MailAddressCollection();
mailBody = bodyx;
try
{
smtpServer = SysEmaiLParameters::find(false).SMTPRelayServerName;// using the SMTP server ip mailMessage = new System.Net.Mail.MailMessage(mailFrom,mailTo);
mailmessage.set_Subject(mailSubject);
mailmessage.set_Body(mailBody);
SMTPPort = SysEmaiLParameters::find(false).SMTPPortNumber;
myMail = new System.Net.Mail.SmtpClient(smtpServer, SMTPPort);
//myMail.set_EnableSsl(true);
// Untuk SSL enabled seperti: gmail, smtp.gmail.com, port 465 or 587
myMail.set_EnableSsl(false);
pwd = SysEmaiLParameters::password();
mymail.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, pwd));
mymail.Send(mailmessage);
}
catch(Exception::CLRError)
{
throw Exception::CLRError;
}
mailMessage.Dispose();
CodeAccessPermission::revertAssert();
}
No comments:
Post a Comment