-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendEmail from Visual Studio
50 lines (48 loc) · 1.63 KB
/
sendEmail from Visual Studio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
namespace SendMail
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter 0 (OrderRequests), P (PaymentReceived), S (ShipmentNotices), R (RestockNotices)");
string input = Console.ReadLine().ToUpper();
string folder = null, subject = null;
switch (input)
{
case "O":
folder = "OrderRequests";
subject = "Order Request";
break;
case "P":
folder = "PaymentReceived";
subject = "Payment Received";
break;
case "R":
folder = "ShipmentReceived";
subject = "Shipment Received";
break;
case "S":
folder = "ShipmentNotices";
subject = " Order Shipped";
break;
default: Console.WriteLine("Nothing to do! Bye."); return;
}
foreach (string fpath in Directory.GetFiles(folder))
SendMessage(fpath, subject);
}
static void SendMessage(string fileName, string subject)
{
string body = File.ReadAllText(fileName);
MailMessage msg = new MailMessage("sender's email", "receiver's email", subject, body);
SmtpClient client = new SmtpClient(". . .");
client.Send(msg);
}
}
}