Hi All,
I am trying to attach PDF and send users a mail along with the attachment.
I am running the below code and I am not getting any error. But the mail is not going to users.
Also I debugged it and after the following code : "smtpClient.Send(mailmessage);" the process is just getting stopped or nothing is happening after the above line of code .
Please let me know what is going wrong .
Please find my whole code below :
void clicked()
{
dialog d = new dialog("Select file");
dialogField dv,dt,dr;
test_PrintDataCustPrcList testMail;
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.Attachment attachment;
System.Net.Mail.AttachmentCollection attachementCollection;
System.Net.Mail.SmtpClient smtpClient;
System.Net.Mail.MailAddress mailAddressFrom;
System.Net.Mail.MailAddress mailAddressTo;
str strBody;
str strSMTPServer;
str strFileName;
str fromAddr,toAddr;
FileIOPermission perm;
;
// breakpoint;
while select testMail
where testMail.CurUserId == XUserInfo::find(false, curUserId()).name && testMail.CheckCust == NoYes::Yes
{
if(testMail)
{
dv = d.addField(typeid(FilenameOpen), "Select file to Attach");
dt = d.addField(typeId(EnterIds),"Enter From Addr");
dr = d.addField(typeId(EnterIds),"Enter To Addr");
//d.addText("Type Receiver Address :",0);
if (d.run())
{
// dv = d.addField(typeid(FilenameOpen), "Select file to Attach");
// dt = d.addField(typeId(EnterIds),"Enter From Addr");
//dr = d.addField(typeId(EnterIds),"Enter To Addr");
fromAddr = dt.value();
toAddr = dr.value();
// preparing parameters
mailAddressFrom = new System.Net.Mail.MailAddress(fromAddr, "");
mailAddressTo = new System.Net.Mail.MailAddress(toAddr,"");
strBody = "There is a email body";
strSMTPServer = "MailServerName";
// preparing mail with body, subject, from, to.
mailMessage = new System.Net.Mail.MailMessage(mailAddressFrom, mailAddressTo);
mailmessage.set_Subject("There is a email subject");
mailmessage.set_Body(strBody);
attachementCollection = mailMessage.get_Attachments();
strFileName = dv.value();
// assert permision
perm = new FileIOPermission(strFileName,'w');
perm.assert();
// attaching file to that email.
attachment = new System.Net.Mail.Attachment(strFileName);
attachementCollection.Add(attachment);
smtpClient = new System.Net.Mail.SmtpClient(strSMTPServer);
Box::info(strfmt("Email Has Been Prepared To be Sent to The Customer with Attached PDF. Cutomer Account ID = %1",testMAil.tmpCustAccount));
smtpClient.Send(mailmessage);
// release permision
CodeAccessPermission::revertAssert();
}
}
}
}
Regards,
Mania