Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29935

How to consolidate multiple emails meant for one email address into one email [closed]

$
0
0

I have a WPF application that can accept orders for a specific product and list down the raw materials needed to manufacture that specific product. If there are not enough materials, the application can send an email to the supplier of each raw material. I can simply send an email for each raw material but there are times where two or more different raw materials come from the same supplier. Instead of emailing that company two or three times, I want to consolidate those emails into one. How should I go about this? Any help would be appreciated, thanks.

Update: @FedericoRossi's suggestion worked out great, now all I have to do is program the email sending part, that should be easy enough.

public class MissingMaterial
    {
        public string Name;
        public string Email;
        public int RequiredQuantity;
    }

 public List<MissingMaterial> GetListOfMissingMaterials()
    {
        List<MissingMaterial> missingMaterialsList = new List<MissingMaterial>();
        foreach (DataRow row in _materialsGridSource.Rows)
        {
            if (int.Parse(row[1].ToString()) > int.Parse(row[2].ToString()))
            {
                MissingMaterial missingMaterial = new MissingMaterial();
                missingMaterial.Name = row[0].ToString();
                missingMaterial.Email = row[4].ToString();
                missingMaterial.RequiredQuantity = int.Parse(row[1].ToString()) - int.Parse(row[2].ToString());
                missingMaterialsList.Add(missingMaterial);
            }
        }
        return missingMaterialsList;
    }
 private void sendEmail()
    {
        var emailGroups = from MissingMaterial in GetListOfMissingMaterials() group MissingMaterial by MissingMaterial.Email;
        foreach (var group in emailGroups)
        {
            Console.WriteLine(group.Key + " - " + group.Count());
            Console.WriteLine("---------");
            foreach(var material in group)
            {
                Console.WriteLine(material.Name + " (" + material.RequiredQuantity + ")");
            }
            Console.WriteLine();
            Console.WriteLine();
        }
    }

Output of GroupBySample screenshot of application

Database


Viewing all articles
Browse latest Browse all 29935

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>