RMA receipt email

Hi all,
I’m trying to join Reason with RMADetail in a data directive for emailing on RMARcpt new records.
In the last join I’m getting errors. I know I can’t join a joined table but I’m not sure how to otherwise get at it.

String nl = Environment.NewLine;
var ttRMARct = (from row in ttRMARcpt
where row.Company == Session.CompanyID
select row).FirstOrDefault();
if(ttRMARcpt != null)
{

        var RMAHead = (from rh in Db.RMAHead
                      join rd in Db.RMADtl
                      on new {rh.Company,rh.RMANum}
                      equals new {rd.Company, rd.RMANum}
                      join cc in Db.CustCnt
                      on new {rh.Company, rh.CustNum, rh.ConNum}
                      equals new {cc.Company, cc.CustNum, cc.ConNum}
                      join cu in Db.Customer
                      on new {rh.Company, rh.CustNum}
                      equals new {cu.Company, cu.CustNum}
                      join re in Db.Reason
                      on new {rd.Company, rd.ReturnReasoCode}
                      equals {re.Company, re.ReasonCode}
                      where rh.Company == Session.CompanyID 
                      && rh.RMANum == ttRMARct.RMANum
                      select new {rh.RMANum,rd.RMALine, rd.PartNum, rd.LineDesc, cc.EMailAddress, cu.Name, rd.ReturnQty, rd.ReturnReasonCode}).FirstOrDefault();
       
          if (RMAHead != null)
          {
          var mailer = this.GetMailer(async: false);
          var message = new Ice.Mail.SmtpMail();
          message.SetFrom("test@eamail.com");
          message.SetTo(RMAHead.EMailAddress);
          message.SetSubject("RMA: " + RMAHead.RMANum + RMAHead.Name + " has been received");
          message.SetBody("<html><body><p> Receipt For:" + " </p></body></html>" + 
                          nl + "<html><body><p>RMA: " + RMAHead.RMANum +  " Receipt Notification." + "RMA: " + ttRMARct.RMANum +" </p></body></html>" + 
                          nl + "<html><body><p>Line: "+ RMAHead.RMALine + "</p></body></html>" + 
                          nl + "<html><body><p>Part: " + RMAHead.PartNum + "</p></body></html>" + 
                          nl + "<html><body><p>Description: " + RMAHead.LineDesc + "</p></body></html>" +                            
                          nl + "<html><body><p>Line Qty:" + Convert.ToDouble(RMAHead.ReturnQty) + "</p></body></html>" +
                          nl + "<html><body><p>Received Qty:" + Convert.ToDouble(ttRMARct.ReceivedQty) + "</p></body></html>");
          mailer.Send(message);
          }
  }

Ok I answered my own question, not sure if there is a better way.

String nl = Environment.NewLine;
var ttRMARct = (from row in ttRMARcpt
where row.Company == Session.CompanyID
select row).FirstOrDefault();

   if(ttRMARcpt != null)
   {
          
        var RMAHead = (from rh in Db.RMAHead
                      join rd in Db.RMADtl
                      on new {rh.Company,rh.RMANum}
                      equals new {rd.Company, rd.RMANum}
                      join cc in Db.CustCnt
                      on new {rh.Company, rh.CustNum, rh.ConNum}
                      equals new {cc.Company, cc.CustNum, cc.ConNum}
                      join cu in Db.Customer
                      on new {rh.Company, rh.CustNum}
                      equals new {cu.Company, cu.CustNum}
                      where rh.Company == Session.CompanyID 
                      && rh.RMANum == ttRMARct.RMANum
                      select new {rh.RMANum,rd.RMALine, rd.PartNum, rd.LineDesc, cc.EMailAddress, cu.Name, rd.ReturnQty, rd.ReturnReasonCode}).FirstOrDefault();
       
          if (RMAHead != null) 
          { var Reason = (from re in Db.Reason
            where re.Company == Session.CompanyID && re.ReasonCode == RMAHead.ReturnReasonCode
            select re).FirstOrDefault();
            
              if(Reason != null)
              {
                var mailer = this.GetMailer(async: false);
                var message = new Ice.Mail.SmtpMail();
                message.SetFrom("emil@test.com");
                message.SetTo(RMAHead.EMailAddress);
                message.SetSubject("RMA: " + RMAHead.RMANum + RMAHead.Name + " has been received");
                message.SetBody("<html><body><p> Receipt For:" + " </p></body></html>" + 
                                nl + "<html><body><p>RMA: " + RMAHead.RMANum +  " Receipt Notification." + "RMA: " + ttRMARct.RMANum +" </p></body></html>" + 
                                nl + "<html><body><p>Line: "+ RMAHead.RMALine + "</p></body></html>" + 
                                nl + "<html><body><p>Part: " + RMAHead.PartNum + "</p></body></html>" + 
                                nl + "<html><body><p>Description: " + RMAHead.LineDesc + "</p></body></html>" +                            
                                nl + "<html><body><p>Line Qty: " + Convert.ToDouble(RMAHead.ReturnQty) + " EA</p></body></html>" +
                                nl + "<html><body><p>Received Qty: " + Convert.ToDouble(ttRMARct.ReceivedQty) + " EA</p></body></html>" 
                                + nl + "<html><body><p>Reason for Return: " + Reason.Description + "</p></body></html>"
                                );
                mailer.Send(message);
              }  
          }
  }

FWIW - Your HTML needs lots of work. There should be just one <html></html> pair, with one <body></body> pair too. Like:

<html>
  <body>
    <p>This is a paragraph. <br>With a line break </p>
  </body>
</html>

Elements don’t need to be on a individual lines, or be indented. That was just for illustration.

And if you want, you can have a <header></header> section (inside of the html tags, and before the body section), and define styles in it.

See:

1 Like

That’s great!
I almost got it working but get an error.

var ttRMARct = (from row in ttRMARcpt
where row.Company == Session.CompanyID
select row).FirstOrDefault();

   if(ttRMARcpt != null)
   {
          
        var RMAHead = (from rh in Db.RMAHead
                      join rd in Db.RMADtl
                      on new {rh.Company,rh.RMANum}
                      equals new {rd.Company, rd.RMANum}
                      join cc in Db.CustCnt
                      on new {rh.Company, rh.CustNum, rh.ConNum}
                      equals new {cc.Company, cc.CustNum, cc.ConNum}
                      join cu in Db.Customer
                      on new {rh.Company, rh.CustNum}
                      equals new {cu.Company, cu.CustNum}
                      where rh.Company == Session.CompanyID 
                      && rh.RMANum == ttRMARct.RMANum
                      select new {rh.RMANum,rd.RMALine, rd.PartNum, rd.LineDesc, cc.EMailAddress, cu.Name, rd.ReturnQty, rd.ReturnReasonCode}).FirstOrDefault();
       
          if (RMAHead != null) 
          { var Reason = (from re in Db.Reason
            where re.Company == Session.CompanyID && re.ReasonCode == RMAHead.ReturnReasonCode
            select re).FirstOrDefault();
            
              if(Reason != null)
              {
                var mailer = this.GetMailer(async: false);
                var message = new Ice.Mail.SmtpMail();
                message.SetFrom("epicalerts@s.com");
                message.SetTo(RMAHead.EMailAddress);
                //message.SetBcc("");
                message.SetSubject("RMA: " + RMAHead.RMANum + RMAHead.Name + " has been received");
                message.SetBody("<html><header><style>table, th, td {border: 1px solid black;font-family: monospace; font-size: 12px;}th, td {padding: 5px;text-align: left;}</style></header><body>Dear " + RMAHead.Name + ",<br><br><br> Your RMA has been recieved with the following information.<br><br><table><body><tr><th>RMA Number </th> <th> Line</th> <th> Part Number</th> <th> Description</th> <th> Line Qty </th> <th> Receipt Qty</th> <th> Reason for Return</th> </tr><tr><td>" + RMAHead.RMANum + "</td><td>" + RMAHead.RMALine + "</td><td>" + RMAHead.PartNum + "</td><td>" + RMAHead.LineDesc + "</td><td>" + Convert.ToDouble(RMAHead.ReturnQty) + "</td><td>" + Convert.ToDouble(ttRMARct.ReceivedQty) + "</td><td> " + Reason.Description + "</td></tr></tbody></table><br><br><br><br><br><br><br> Regards, <br><br> Sierra RMA Email Notification</body></html>");
                mailer.Send(message);
              }  
          }
  }

image

I’d use StringBuilder to make the message bod, adding a few parts at a time. Building up the message body a little bit at a time, and see when it stop working.

Not sure, but you might need line breaks or spacing between the style definitions.

1 Like

I got it with some help from a friend.

var ttRMARct = (from row in ttRMARcpt
where row.Company == Session.CompanyID
select row).FirstOrDefault();

   if(ttRMARcpt != null)
   {
         
        var RMAHead = (from rh in Db.RMAHead
                      join rd in Db.RMADtl
                      on new {rh.Company,rh.RMANum}
                      equals new {rd.Company, rd.RMANum}
                      join cc in Db.CustCnt
                      on new {rh.Company, rh.CustNum, rh.ConNum}
                      equals new {cc.Company, cc.CustNum, cc.ConNum}
                      join cu in Db.Customer
                      on new {rh.Company, rh.CustNum}
                      equals new {cu.Company, cu.CustNum}
                      where rh.Company == Session.CompanyID
                      && rh.RMANum == ttRMARct.RMANum
                      select new {rh.RMANum,rd.RMALine, rd.PartNum, rd.LineDesc, cc.EMailAddress, cu.Name, rd.ReturnQty, rd.ReturnReasonCode}).FirstOrDefault();
      
          if (RMAHead != null)
          { var Reason = (from re in Db.Reason
            where re.Company == Session.CompanyID && re.ReasonCode == RMAHead.ReturnReasonCode
            select re).FirstOrDefault();
           
              if(Reason != null)
              {
                var mailer = this.GetMailer(async: false);
                var message = new Ice.Mail.SmtpMail();
                message.SetFrom("epicalerts@s.com");
                message.SetTo(RMAHead.EMailAddress);
                //message.SetBcc("");
                message.SetSubject("RMA: " + RMAHead.RMANum + "for " + RMAHead.Name + " has been received");
                message.SetBody("<html><header><style>table, th, td {border: 1px solid black;font-family: monospace; font-size: 12px;}th, td {padding: 5px;text-align: left;}</style></header><body>Dear " + RMAHead.Name + ",<br><br><br> Your RMA has been recieved with the following information.<br><br><table><body><tr><th>RMA Number </th> <th> Line</th> <th> Part Number</th> <th> Description</th> <th> Line Qty </th> <th> Receipt Qty</th> <th> Reason for Return</th> </tr><tr><td>" + RMAHead.RMANum + "</td><td>" + RMAHead.RMALine.ToString() + "</td><td>" + RMAHead.PartNum + "</td><td>" + RMAHead.LineDesc + "</td><td>" + Convert.ToDouble(RMAHead.ReturnQty).ToString() + "</td><td>" + Convert.ToDouble(ttRMARct.ReceivedQty).ToString() + "</td><td> " + Reason.Description + "</td></tr></tbody></table><br><br><br><br><br><br><br> Regards, <br><br> Sierra RMA Email Notification</body></html>");
                mailer.Send(message);
              } 
          }
  }

the .ToString() was needed

1 Like