This is Code to send mail From Enterprise portal web page using dataset in axapta. Following code you can write in ascx page and you can get required mail parameter from dataset by writing data method with return values.
string fromId, toId, smtpHost, userIdpw, Body;
int smtpport;
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
fromId = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("fromEmailId");
toId = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("toEmailId");
smtpHost = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("smtpHost");
smtpport = (int)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("smtpport");
userIdpw = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("userIdpw");
Body = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("emailBody");
try
{
MailAddress fromAddress = new MailAddress(fromId);
message.From = fromAddress;
message.To.Add(toId);
message.Subject = "Test";
message.IsBodyHtml = true;
message.Body = Body;
smtpClient.Host = smtpHost;
smtpClient.Port = smtpport;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential(fromId, userIdpw);
smtpClient.EnableSsl = true;
smtpClient.Send(message);
Proxy.Info info = new Proxy.Info(AxSession.AxaptaAdapter);
info.add(Proxy.Exception.Info, "Email has been sent Successfully");
}
catch (Exception ex)
{
Proxy.Info info = new Proxy.Info(AxSession.AxaptaAdapter);
info.add(Proxy.Exception.Info, "Error in Sending Mail");
}
string fromId, toId, smtpHost, userIdpw, Body;
int smtpport;
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
fromId = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("fromEmailId");
toId = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("toEmailId");
smtpHost = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("smtpHost");
smtpport = (int)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("smtpport");
userIdpw = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("userIdpw");
Body = (string)this.DatasetNm.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("emailBody");
try
{
MailAddress fromAddress = new MailAddress(fromId);
message.From = fromAddress;
message.To.Add(toId);
message.Subject = "Test";
message.IsBodyHtml = true;
message.Body = Body;
smtpClient.Host = smtpHost;
smtpClient.Port = smtpport;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential(fromId, userIdpw);
smtpClient.EnableSsl = true;
smtpClient.Send(message);
Proxy.Info info = new Proxy.Info(AxSession.AxaptaAdapter);
info.add(Proxy.Exception.Info, "Email has been sent Successfully");
}
catch (Exception ex)
{
Proxy.Info info = new Proxy.Info(AxSession.AxaptaAdapter);
info.add(Proxy.Exception.Info, "Error in Sending Mail");
}