I am creating an application to send a mass message. The users are being loaded into a listbox. I am loading it into a listbox so I can choose who to and who not to send messages to. Here is what I have.
foreach (User user in axSkype1.Friends)
{
foreach (String friends in listBox1.SelectedItems)
{
if (richTextBox2.Text.Contains("{username}"))
{
axSkype1.SendMessage(friends, richTextBox2.Text.Replace("{username}", "") + user.FullName + " " + "\n\n" + "" + flatTextBox1.Text + "\n\n" + richTextBox1.Text);
}
else
{
axSkype1.SendMessage(friends, richTextBox2.Text + "\n\n" + flatTextBox1.Text + "\n\n" + richTextBox1.Text);
}
}
}
The part where it says user.FullName is what I am having trouble with. When it sends the message it send the message to the person selected but it sends it for how ever many contacts I have. I just want it to send one but with the users FullName.
Related
The problem started here:
https://learn.microsoft.com/en-GB/office365/servicedescriptions/exchange-online-service-description/exchange-online-limits#receiving-and-sending-limits
Office365 allows an email account to send 10,000 emails within 24 hours and the rate limit is 30 emails per 60 seconds.
My idea is to
create a Queue to hold the emails.
single thread that access the DB, fetch emails, and append to the Queue.
10 threads, each will access the Queue (each 3s), and send an email using its own email account.
Now I can guarantee that each email account (thread) will send maximum 20 emails per 60 seconds.
If the Queue is full (eg. 10000 emails), all email accounts (threads) will work similarly and as expected as they find emails when they try to access the Queue, while if the Queue is empty, there will be different in the processed emails count for each thread. How can I pause all threads when the Queue is empty to make sure that all email accounts (threads) will be used similarly.
Or if there are better ways to achieve this ?
using Message = KeyValuePair<long, Email>;
static ConcurrentQueue<Message> emails_queue = new ConcurrentQueue<Message>();
static Thread GetDBEmailsThread;
static void SendEmails1()
{
while (true)
{
if (emails_queue.Count == 0)
{
Console.WriteLine(DateTime.Now + " " + Thread.CurrentThread.Name + " - " + "Sleeping for 5s");
Thread.Sleep(5000);
continue;
}
try
{
Message msg;
// process messages
// we use Try here because we're multithreaded
// so it's possible that between the Wait() call
// and the dequeue call the queue may be cleared
if (emails_queue.TryDequeue(out msg))
{
Email email = msg.Value;
Console.WriteLine(DateTime.Now + " " + Thread.CurrentThread.Name + " - " + "is handling : " + msg.Key + " - " + email.Subject);
// Done, move email to sent items
SendEmail(email, Constants.SS_EMAIL_1);
Console.WriteLine(DateTime.Now + " " + Thread.CurrentThread.Name + " - " + "email " + msg.Key + " - " + "sent.");
}
}
catch (Exception e)
{
Console.WriteLine(DateTime.Now + " " + Thread.CurrentThread.Name + " - " + " " + "Exception. \r\n" + e.Message);
}
finally
{
Thread.Sleep(3000);
emails_queue_available.Release();
}
}
}
I am using C# MVC Architecture.
I am going to retrieve the questions from the database and display in the email content as a list of questions.
Below is the method of the email template.
public bool SendJobAcceptanceToRecruiter(string recruiterName, string recruiterEmail, string jobTitle,string joblink, string mailBody, string organization, List<JobQuestion> ques)
{
string subject = "Job Advert Accepted - " + jobTitle + "-" + organization;
var generaltemplate = GetEmailTemplate("GENERAL EMAIL TEMPLATE");
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: " + ques + "<br/>" +
"<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
body = body.Replace("#Orgname", organization);
body = body.Replace("#JobLink", joblink) + GetEmailFooter();
var result = _emailProvider.SendEmail(recruiterEmail, subject, body, true);
return result;
}
Here for the List of questions, I get the questions as below.
I want to display the 'Question' in the second image as list of questions(In the above case as the count is 7,want to display the 7 questions) with numbering starting from 1.(Number of questions may differ according to the advert.) as a list in the email content.
Every other details(jobTitle,JobLink,RecruiterEmail etc..) are displayed in the email.
Only the 'ques' under Questions Posted: in the email content are displayed as
[![enter image description here][3]][3]
I want the content to be displayed as,
1.Question 1
2.Question 3
3.Question 3
...
How can I solve this?
You need to "unfold" the list of questions, if you do that, you'll have all the freedom you need.
In stead of:
"<br/>Questions Posted: " + ques + "<br/>"
use something like this:
"<br/>Questions Posted: " + string.Join(", ",Enumerable.Range(0, ques.Count()).Select(n => n.Description).ToArray()) + "<br/>"
Or for better readability:
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: ";
foreach(var question in ques)
template += $"somthing {question.Description} something"
template += "<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
Further optimization: use a StringBuilder:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
foreach(var question in ques)
{
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());
Addition: for numbering you have various options. Here's a simple one to understand:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
int number = 0;
foreach(var question in ques)
{
sb.AppendLine($"QUESTION {++number}");
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());
Same ASP.NET MVC 4 website, same mail send code. Sending e-mail messages from AccountController is not working anymore, from all the other controllers it is.
Here is the error I get from AccountController actions:
Cannot send e-mail from noreply#domain.com to bill#microsoft.com
Exception: Mailbox unavailable. The server response was: 5.7.1 Unable to relay.
mail.domain.com, SMTPSVC/mail.domain.com, 25,
What should I check? It worked from years but with a recent Windows Server 2008 / Exchange 2010 update is not working anymore.
MailMessage message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = isHtml
};
try
{
smtpClient.Send(message);
string errorMsg = "Sending e-mail from " + fromAddress.Address + " to " + originalAddresses[i];
errorMsg += Environment.NewLine;
errorMsg += smtpClient.Host + ", " + smtpClient.TargetName + ", " + smtpClient.Port + ", " + smtpClient.ClientCertificates + ", " + smtpClient.EnableSsl + ", " + smtpClient.UseDefaultCredentials + ", " + smtpClient.Timeout;
sw.WriteLine(errorMsg)
}
catch (Exception ex)
{
string errorMsg = "Cannot send e-mail from " + fromAddress.Address + " to " + originalAddresses[i] + ", " + "Exception: " + ex.Message +
(ex.InnerException != null ? ", " + ex.InnerException.Message : string.Empty);
errorMsg += Environment.NewLine;
errorMsg += smtpClient.Host + ", " + smtpClient.TargetName + ", " + smtpClient.Port + ", " + smtpClient.ClientCertificates + ", " + smtpClient.EnableSsl + ", " + smtpClient.UseDefaultCredentials + ", " + smtpClient.Timeout;
sw.WriteLine(errorMsg);
return false;
}
Any idea of what should I check? Has AccountController something special I should care about? Is the [RequireHttps] controller action attribute somewhat involved?
Thanks.
EDIT1:
Here are our Exchange 2010 settings (please note that we can send the same e-mail message from other ASP.NET MVC controllers):
https://practical365.com/exchange-server/how-to-configure-a-relay-connector-for-exchange-server-2010/
EDIT2:
I was wrong, the problem is not ASP.NET MVC controller related but e-mail address domain related. I discovered that the all the times we include an e-mail address that doesn't belong to our company domain (the outer internet) we get the error above. So now the question is: why the Exchange 2010 Receive Connector is now unable to send e-mail notification to the outer internet?
The server farm changed the outgoing IP address of our server and this was blocking all e-mail messages that contain a recipient not in our company domain. Adding the new outgoing IP address to the Exchange 2010 Receive Connector under Properties->Network->Receive mail from remote servers that have these IP addresses solved the problem.
I am attempting to have specific event logs that contain a username that are Security Audit Failures from a DC, in powershell I can easily do this with something like this:
Where the variables would be something like: $DC = "MyDomainController" and $user = "jdoe"
Get-WinEvent -ComputerName $DC -FilterHashtable #{Logname='Security';Keywords='4503599627370496';Data=$user} -MaxEvents 4 | Format-List -Property ID, TimeCreated, MachineName, Message
This would pull 4 event logs that are security audit failures with the person's username from a DC I am looking at, however I have been unable to find or reproduce this behavior to something similar in vb.net, I have been searching pages for the last few days and coming up with a lot of writing and pulling all logs on DC's but not filtering down, any help or guidance would be great, thank you!
I was able to find the answer to this by looking at custom log query's by using xpath, I did the following in C# but the same can be applied in VB, Domaincontroller.text = The domain controller your looking up: Username.text = The AD username to lookup Statustextbox = I have all the logs go to a textbox to read but you could do something like console.writeline
private void LookupLogs_Click(object sender, EventArgs e)
{
Statustextbox.Clear();
string query = "<QueryList>" +
" <Query Id=\"0\" Path=\"Security\">" +
" <Select Path=\"Security\">" +
" *[System[band(Keywords,4503599627370496)]] and *[EventData[Data[#Name='TargetUserName'] and (Data='" + Username.Text + "')]]" +
" </Select>" +
" </Query>" +
"</QueryList>";
EventLogSession session = new EventLogSession(DomainController.Text);
EventLogQuery evntquery = new EventLogQuery("Security", PathType.LogName, query);
evntquery.Session = session;
try
{
EventLogReader logreader = new EventLogReader(evntquery);
DisplayEventAndLogInformation(logreader);
}
catch (Exception ex)
{
MessageBox.Show("An exception occured: " + ex.Message);
}
}
private void DisplayEventAndLogInformation(EventLogReader logReader)
{
for (EventRecord eventInstance = logReader.ReadEvent();
null != eventInstance; eventInstance = logReader.ReadEvent())
{
Statustextbox.AppendText(Environment.NewLine + Environment.NewLine);
Statustextbox.AppendText("---------------------------------------------------------------------------------------------------------------------------------------------------------------" + Environment.NewLine);
Statustextbox.AppendText("Event ID: " + eventInstance.Id + Environment.NewLine);
Statustextbox.AppendText("Publisher: " + eventInstance.ProviderName + Environment.NewLine);
try
{
Statustextbox.AppendText("Description: " + eventInstance.FormatDescription() + Environment.NewLine);
}
catch (EventLogException ex)
{
Statustextbox.AppendText("An exception was thrown: " + ex.Message + Environment.NewLine);
}
EventLogRecord logRecord = (EventLogRecord)eventInstance;
Statustextbox.AppendText(Environment.NewLine);
Statustextbox.AppendText("Container Event Log: " + logRecord.ContainerLog + Environment.NewLine);
}
}
Hi thanks for viewing my question! I'm having a little trouble getting multiple data from my database. I'm trying to show multiple data in a single text box and it will not let me, of course.
My code:
string authorised = "notReviewed";
SundownDatabaseEntities5 dbb = new SundownDatabaseEntities5();
System.Windows.Forms.Form ff = System.Windows.Forms.Application.OpenForms["Login"];
int idd = Convert.ToInt32(((Login)ff).idTb.Text);
var getrecordd = dbb.Holidays.Where(a => a.Id == idd).SingleOrDefault();
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text = "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
FirstOrDefault(); gets the first data it finds but I need them all. How would I go about making it so that it will show multiple data instead of one? Thanks guys!
e.g. Text box:
Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...
Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been authorised.
You can get all records and then use foreach.
var getrecordds = dbb.Holidays.Where(a => a.Id == idd).ToList();
foreach (var getrecordd in getrecordds)
{
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it..."
}
}
Or use ForEach method
dbb.Holidays.Where(a => a.Id == idd).ForEach ( x =>
{
if (x.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it..."
}
});