I have some public const strings in c# console application as shown below:
//Account one
public const string POP_USER1 = "[email protected]";
public const string POP_PWD1 = "abc";
//Account two
public const string POP_USER2 = "[email protected]";
public const string POP_PWD2 = "xyz";
//Account three
public const string POP_USER3 = "[email protected]";
public const string POP_PWD3 = "pqr;
We are using c# MailMan to retrieve emails present in those accounts. I simply wrote a for loop 3 times:
for (int i = 1; i <= 3; i++)
{
eEmails obj = new eEmails (i);
}
In the constructor of eEmails, I am writing the below logic:
public eEmails (int counter)
{
MailMan obj = new MailMan()
obj.PopUsername = "POP_USER" + counter;
obj.PopPassword = "POP_PWD" + counter;
}
The lines where I am assigning user name and passwords, I need to fetch the exact const variable (i.e., POP_USER1, POP_USER2, POP_USER3 etc.,)
However I am not able to get the variable dynamically. I can simply write 3 if blocks in eEmails (int counter), but I didnt like that way. can somebody advise a better way of handling this situation without using separate if blocks for each user??
String[] POPUSER = new String[] {"User1","User2","User3"};and the same for passwords) would do the trick. I think it is the simplest solution. Note, however, that defining the passwords unencrypted in the source code is not safe.eEmailsimplementation has a bug. You are assigning the password to the username property.