Email is sending sucessfully but it is receiving it when we are send it from salesforce

I have a button in LWC component when i click the button LWC form will open when we filled and submit the form Email has to send but email is send sucessfully in debug logs but email is not receving. i checked all the junk folder also but not receiving

@AuraEnabled(cacheable=true)
public static string sendEmail(String AccountName,String AccountPhone,String AccountAddress,String AccountCity,String AccountState,String AccountZip,String ServiceDelivery,String ServiceNeeded,String AdditionalComments,String RequestedBy,String ServiceDate,String LocationofParts,String CurrentDate,String userName,string threadid,Id caseId){
String marketEmail=”;
Case caseData = [Select Id, Legacy_Account_Ship_To__c from Case where Id=: caseId LIMIT 1];
System.debug(‘legacy is ‘+caseData);
if(caseData != null && caseData.Legacy_Account_Ship_To__c != null){
list < Market_Configuration__mdt > marketConfigList = [SELECT Id, MasterLabel, DeveloperName,Fulfiller_Id__c,Service_Delivery_Distro__c FROM Market_Configuration__mdt where Fulfiller_Id__c=:caseData.Legacy_Account_Ship_To__c and MasterLabel !=’ASHCOMM’ and MasterLabel !=’Blank’];
if(!marketConfigList.isEmpty()){
marketEmail = marketConfigList[0].Service_Delivery_Distro__c;
System.debug(‘Service Delivery Distro: ‘ + marketConfigList[0].Service_Delivery_Distro__c);
}
}

     List<String> recordIdList = ServiceDelivery.split(',');
     List<ProductLineItem__c> productLineItems = [SELECT Item_SKU__c,Sales_Order_Number__c FROM ProductLineItem__c WHERE Id IN :recordIdList];

     System.debug('the product line items are '+productLineItems);
    System.debug('ServiceNeeded '+ ServiceNeeded );
    System.debug('AdditionalComments '+ AdditionalComments);
    System.debug('RequestedBy ' + RequestedBy);
    System.debug('ServiceDate ' + ServiceDate );
    System.debug('LocationofParts '  + LocationofParts);
    System.debug('CurrentDate ' + CurrentDate);
    System.debug('userName ' + userName);
   String productLineItemsHTML = '';
   for(ProductLineItem__c item : productLineItems) {
    productLineItemsHTML += '<tr>' +
                             '<td style="text-align: center;">' + item.Item_SKU__c + '</td>' +
                             '<td style="text-align: center;">' + item.Sales_Order_Number__c + '</td>' +
                           '</tr>';
}

String messageBody =
‘Service Delivery’ +
” +
‘ .highlighted-heading { font-size: 24px; font-weight: bold; background-color: #ffbf00;text-align: center;}’ +
‘ .mytable, .mytable1 { width: 100%; }’ +
‘ .mytable th, .mytable td, .mytable1 th, .mytable1 td {padding: 5px; }’ +
‘ .thead { background-color: #f2f2f2; }’ +
‘ .checkbox-cell { display: flex; align-items: center; }’ +
‘ .small-checkbox { margin-right: 8px; }’ +
‘ .from { font-weight: bold; background-color: #ffbf00;}’ +
” +
” +
‘ ‘ +
‘ ‘ +
‘ Service Delivery’ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ From:’ +
‘ Brandon Warehouse’ +
‘ Customer’s Name:’ +
‘ ‘ + AccountNameWithCommas + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ 2998 Broadway Center Blvd’ +
‘ Address:’ +
‘ ‘ + AccountAddress + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Brandon, FL 33510’ +
‘ ‘ +
‘ ‘ + AccountCity + ‘, ‘ + AccountState + ‘ ‘ + AccountZip + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Phone Number:’ +
‘ ‘ + AccountPhone + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Item Number’ +
‘ Sale Order’ +
‘ ‘ +
productLineItemsHTML +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Service Needed’ +
‘ Additional Comments’ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ + ServiceNeeded + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ + AdditionalComments + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Requested By:’ +
‘ ‘ + userName + ” +
‘ Date:’ +
‘ ‘ + currentDate + ” +
‘ ‘ +
‘ ‘ +
‘ Service Date:’ +
‘ ‘ + ServiceDate + ” +
‘ Location of parts:’ +
‘ ‘ + LocationofParts + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
” + threadid + ”+
” +
”;

if(marketEmail == ''){
  return 'No market email found for the given case.';
}

    /*Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
      message.toAddresses = new String[] {marketEmail}; 
     message.subject = 'Service Delivery Request';
     message.HtmlBody = messageBody;
      Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
      Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);*/
      OrgWideEmailAddress owea = new OrgWideEmailAddress();
      try {
          owea = [SELECT Id,DisplayName FROM OrgWideEmailAddress Where DisplayName = '**************'];
      } catch(Exception e) {
      }
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
      message.toAddresses = new String[] {marketEmail}; 
      message.subject = ' Service Delivery Request';
      message.HtmlBody = messageBody;
      message.setSaveAsActivity(true);
      message.setWhatId(caseId);
      if(owea != null){
          System.debug('owea is not null');
          message.setOrgWideEmailAddressId(owea.Id);
      }
      
      Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
      Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
      String messageOutput;
      String emailAddress = message.toAddresses != null && message.toAddresses.size() > 0 ? message.toAddresses[0] : 'unknown';
      System.debug(emailAddress);
      for(Messaging.SendEmailResult res:results){
          if(res.isSuccess()){
             messageOutput = 'Email sent successfully';
            System.debug('Email sent successfully '+emailAddress);
            return messageOutput;
          }else{
               messageOutput = 'Email Sent Failed';
              System.debug('Email Sent Failed');
              return messageOutput + '. Market Email: ' + marketEmail;
            }
          }
          return 'Unknown error';

    


  }

New contributor

Deena Vicky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật