-2

I want to send emails with waiting like this:

You get the all receiver list from a .txt file and you set a time (for example: 50 seconds and 20 people) It needs to send email to 20 people and wait for 50 seconds then continue to send mails from that list.

I think it needs to be before then this code:

SmtpServer.Send(message);

like wait for a while then continue to send emails...

I don't know maybe standard System.Net.Mail library doesn't have a function like this. Maybe we can use EASendMail library but i haven't got any information about using it.

FOR ANOTHER EXAMPLE: Imagine that I'm a company which needs to send 1000 mails to workers. If I send it directly My IP will get red listed and my mails goes to "SPAMBOX" and my workers can't see my important mail. I need to send them like this way : Send 10 workers then wait for 1 minute after that continue to send 10 workers and wait for 1 minute... It needs to go like this. But I can't find a way to do this.

Can you help me?

Portostor
  • 23
  • 4
  • Please provide a [minimal, complete and verifiable example.](https://stackoverflow.com/help/mcve) – Henrik Wilshusen Jan 21 '19 at 10:43
  • You need a service or a background running application to fulfill this kind of requirement. A detailed answer is only possible with detailed question ;-) – schlonzo Jan 21 '19 at 10:44
  • `Thread.Sleep`? – mjwills Jan 21 '19 at 10:47
  • Use a mailing service like [mailchimp](https://mailchimp.com/) – Liam Jan 21 '19 at 11:01
  • Why do you want to wait 50 seconds? Why not just send them all? – mjwills Jan 21 '19 at 11:03
  • Sounds like a spam bot. Expect your ip address to be red listed pretty quickly – Liam Jan 21 '19 at 11:07
  • For example I'm a company and I need to send **1000** mails to my workers. If I try to send it directly to **1000** workers. It will get red listed and spam quickly and my workers can't see it when it goes to spambox. So I need to manage it like this : Send it **10** people then wait for 1 minute then send it **10** more people and wait for **1** minute... But I can't modify `SmptServer.Send(message);` If I try thread.sleep it won't continue where it left. Maybe it works but I don't know how to use it properly. – Portostor Jan 22 '19 at 04:46

1 Answers1

-1

Finally after doing some research I come to this code. Basically I have two variables(peopleToWait and secondsToWait) and list of receivers (through which I am looping). I have created a small SendMail method for sending emails. Here is code:

  static void Main(string[] args)
    {

        var receivers = new List<List<string>>();

        var group1 = new List<string>();
        group1.Add("Email1");
        group1.Add("Email2");
        group1.Add("Email3");

        receivers.Add(group1);
        var group2 = new List<string>();

        group2.Add("Email4");
        group2.Add("Email5");
        group2.Add("Email6");

        receivers.Add(group2);

        var group3 = new List<string>();
        group3.Add("Email7");
        group3.Add("Email8");
        group3.Add("Email9");
        receivers.Add(group3);

        var group4 = new List<string>();
        group4.Add("Email10");
        group4.Add("Email11");
        group4.Add("Email12");
        receivers.Add(group4);

        var secondsToWait = 3;

        foreach (var receiver in receivers)
        {
            ParameterizedThreadStart pts = new ParameterizedThreadStart(SendMail);
            Thread th = new Thread(pts);
            th.Start(receiver);

            Thread.Sleep(secondsToWait * 1000);
        }


        Console.ReadLine();
    }

    static void SendMail(object Email)
    {

        var group = (List<string>)Email;

        //MailMessage abcd = new MailMessage();
        //abcd.To.Add(String.Join(",", group));
        Console.WriteLine("Sending Mail to " + String.Join(",", group));
    }
Gaurav
  • 782
  • 5
  • 12
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/187154/discussion-on-answer-by-gaurav-how-can-i-send-emails-with-waiting-time-in-c). – Samuel Liew Jan 23 '19 at 01:20