implementing "Reply this by email" for a ticket - c#

I'm going to develop a ticketing system with c# that should send an email containing the ticket content to the receiver upon ticket submission and the receiver should be able to reply to that email which results in sender receiving the email of the reply. What puzzles me is that how am I going to keep track of that specific ticket which being replied by the receiver. I'm not looking for any code, just concepts or best practices.

Theoretically, you might use the Message-ID in conjunction with In-Reply-To, as described in the RFC 5322:
The "Message-ID:" field provides a unique message identifier that
refers to a particular version of a particular message. The
uniqueness of the message identifier is guaranteed by the host that
generates it (see below). This message identifier is intended to be
machine readable and not necessarily meaningful to humans. A message
identifier pertains to exactly one version of a particular message;
subsequent revisions to the message each receive new message
identifiers.
The "In-Reply-To:" and "References:" fields are used when
creating a reply to a message. They hold the message identifier of
the original message and the message identifiers of other messages
(for example, in the case of a reply to a message that was itself a
reply). The "In-Reply-To:" field may be used to identify the message
(or messages) to which the new message is a reply, while the
"References:" field may be used to identify a "thread" of
conversation.
When creating a reply to a message, the "In-Reply-To:" and
"References:" fields of the resultant message are constructed as
follows:
The "In-Reply-To:" field will contain the contents of the
"Message-ID:" field of the message to which this one is a reply (the
"parent message"). If there is more than one parent message, then the
"In-Reply-To:" field will contain the contents of all of the parents'
"Message-ID:" fields. If there is no "Message-ID:" field in any of the
parent messages, then the new message will have no "In-Reply-To:"
field.
Of course, you should keep tracking of mappings between the Message-ID field and you internal ticket number in a separate database table.
Example
A new email E1 is sent from yourCompany.com.
A reply R1 is received from yahoo.com. The message header information:
References:
<11111#yourCompany.com>
Message-ID:
<22222#webServer.yahoo.com>
In-Reply-To:
<11111#yourCompany.com>
A reply R2 to R1 is sent from yourCompany.com.
A reply R3 to R2 is received from yahoo.com. The message header information:
References:
<11111#yourCompany.com>
<22222#webServer.yahoo.com>
<33333#yourCompany.com>
Message-ID:
<44444#webServer.yahoo.com>
In-Reply-To:
<33333#yourCompany.com>

I think the only way to do this (and I never saw a ticketing-system who does that differently) is adding the ID into the subject-line.
In our case, we have subject-headers like "bla bla bla <<< CALLID: 12312 >>>".
With regex, that's quite easy to catch

Keep the ticket in the Subject in a specific format that the application can understand.
e.g. Subject can be Close TICKET T1 or
Reject Resolution TICKET T1 .
You can ask the customer to specify the reason in the mail body.
the trick is to give pre-formatted Subject which you understand.

Related

Access previous message content from a user reply message on Telegram

Does anyone know how can I access a previous message content when a user sends a reply message on Telegram?
for example:
James: hello
me: reply on James message with "hello friend"
here i want to get the hello message content or its message id in my telegram bot to process a command.
sth like this:
if(message.Contains("/delete")){
bot.DeleteMessageAsync(chatId, PreviousMessage or OriginalMessage ID)
}
PreviousMessage or OriginalMessage ID are equals to MessageId
but instead of MessageId i want to use sth like those two
I have checked telegram bot documentation and I did not find anything
How can i do it?
(Im using getUpdates method)
sorry for my poor English
You can find the original message ID in message.reply_to_message.message_id. Naming could differ depends on the library you use. More information and other attributes that could be useful you can find in the official Telegram's documentation for the Message object.

The specified string is not in the form required for an e-mail address. with valid address

I am developing a software which send email after the user pressed a button.
I encounter some issues with these emails: they sometimes raise this exception: The specified string is not in the form required for an e-mail address.. I emphasise on sometimes because they actually works sometimes.
Surprising thing is that the mail addresses are actually correctly formatted: they all look like blahblah#domain.com or Blah Blah <blahblah#domain.com>. This even happens with some of my company's mails, which - of course - are valid. I even checked all the addresses with this regex and they all passed: ^\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*$.
Here are the steps my software is going through:
Add the main address:
var mail = new MailMessage(new MailAddress("logistics#company.com", "company logistics department"), new MailAddress(address));
Here the address is valid since the software did send an email to this address prior to this step.
In a loop I add the CCs addresses:
mail.CC.Add(new MailAddress(email));
Here I applied a null/empty check so I am not adding any empty mail address.
And finally I add myself in BCC address:
mail.Bcc.Add("my#company.com");
Is there any issue in the way I'm doing this ?
Are there some known issues (additionnaly random ones) about the C# .NET mail class?
Is there a limit on the maximum amount of To / CC / Bcc addresses this class can handle ?
EDIT: i'm using System.Net.Mail classes

Read And Write To Header Message MQ C#

I am reading an MQMessage in like so
queue.Get(message, gmo);
string message1 = message.ReadString(message.MessageLength);
I can see there is a message.UserId on MQMessage, but that is not enough
I want the users to get additional information in the message header of an MQMessage.
How can I set and then retrieve the following from a header of an MQMessage
username
password
mySpecialID
This can be done like this
msg.SetStringProperty("NicksProp", "blahblah");
Note: MQ treats message properties as plain text, so if you are sending a password as a message property then EVERYONE can see it. You will be able to see it via WireShark, and/or in the queue with any tool (MQ Explorer) and/or in the MQ log files.

Sending multiple emails with transaction behavior (if one fails no emails get send)

Sorry if I failed to find an existing post with my problem.
What am I trying to do is as follows:
I simply want to send a couple of emails (2-3) to different people and more importantly with different content. The emails are official, important and also logged in the system. Long story short, I need when for some reason one of them fails to stop the sending of the others. I need either all of them sent or none of them.
What have I done so far
It is not the first time the system I worked on has to send an automatic email. The application is an ASP MVC website. So some time ago, I installed the MvcMailer (MvcMailer) and used it the way it was explained. It worked quite well and so I liked the idea of previewing the email (as you can give it a view to send).
So, in the light of my new problem I read carefully the MvcMailer documentation and did not find anything about sending multiple emails in transaction-like manner. Couldn't think of a way to force them to behave in this way. In my tests when I send an email, even if it is one email with a few CCs, all working mails get send and just one of them fails (wrong email name, closed port ... whatever).
I was hoping someone could suggest me a way to achieve something like this. I hope my explanation was sufficient and if not, let me know I will provide you with all details required.
If this is impossible with the MvcMailer, then is it possible with other tools ?
My implementation so far: (keep in mind I'm still in the testing stages)
public class MailerController : Controller
{
private MailerRepository mailerRep;
public MailerController()
{
this.mailerRep = new MailerRepository();
}
public void TestTransmittalEmail()
{
var model = this.mailerRep.GetTransmittalModel(1234); //I've stucked a specific clientId
var mailer = new TransmittalsMailer();
mailer.TransmittalEmail(model).Send();
}
}
public class TransmittalsMailer : MailerBase
{
public TransmittalsMailer()
{
}
public MvcMailMessage TransmittalEmail(TransmittalManifestModel model)
{
var mailMessage = new MvcMailMessage() { Subject = "Transmittals - TESTING EMAIL" };
//embedding a few images in the email
var resources = new Dictionary<string, string>();
resources["logo"] = PDFResourcePaths.VripackLogo;
resources["companyInfo"] = PDFResourcePaths.CompanyInfoBlock;
mailMessage.To.Add("test1#email.com");
mailMessage.Attachments.Add(new Attachment(#"D:\ASD\TransmittalFolders\1\Archives\150812.1433.MMA.rar"));
ViewData["model"] = model;
this.PopulateBody(mailMessage, "TransmittalEmailView", resources);
return mailMessage;
}
}
This is actually quite a difficult problem to solve. This is because when you send an email, it will work as long the SMTP server can be found (no exception will be thrown).
So you basically have to wait some arbitrary amount of time, and check the inbox of the email you sent it from for the delivery failure. If there is a delivery failure, you stop sending.
So long story short, you shouldn't probably do this. You should simply send all three and notify yourself some other way (probably another email) that there was a failure and which email failed.
You can check if an exception is thrown and then cancel the sending of subsequent emails until the issue is addressed. However this only deals with issues on your end on the sending of each email individual email. If the first two mails are successfully sent, and the last throws an exception, you can't unsend the first emails.
A possible workaround (ugly as it is) would be to initially send emails to an email address you control. If an exception is thrown at this step, log the error, and do not send any further emails until the error is dealt with. If no exceptions are raised, send the emails. However this does not and cannot handle issues that may occur on the recipients side.
A delivery failure notice is not guaranteed as depending on the configuration of your SMTP and the recipient SMTP a delivery failure notification might not be sent. Even if delivery failure notifications are enabled, the notification might not be sent for days (in one of my previous jobs, email delivery failure notifications were not sent until 14 days had elapsed).
Ideally, this should be dealt with at the initial input of the email addresses before you ever send any documents to anyone. You simply send a verification email to the email address in question and have the user clicking on a verification link back to a web service you control. Until this has been done, you don't send any emails to the intended recipient.

Why Does SmtpFailedRecipientException.FailedRecipient Include Angle Brackets?

I have a .NET 4.0 application which sends email with the SmtpClient.Send() method. Sometimes our SMTP server will return an error like "550 Unknown user", so I wrote a handler which catches SmtpFailedRecipientsException and looks at the FailedRecipient property of each of the SmtpFailedRecipientException objects within SmtpFailedRecipientsException.InnerExceptions, to determine if the failure was because of a To address, a CC address, or a Bcc address. (We want to handle BCC failures separately.)
The FailedRecipient property is documented to be "A String that contains the e-mail address." However, I've found that my attempts to determine which kind of recipient failed is failing because FailedRecipient is including angle brackets, so it looks like "<failedrecipient#domain.com>" instead of "failedrecipient#domain.com"! Is it correct that that property should include angle brackets, so that all consumers of that property have to check to see if they're there and then strip them off before it's useful?
EDIT
Ugh... okay, if referencesource.microsoft.com is to be believed, and the code hasn't changed from 4.0 to 4.5.1, then I think I've found what's causing the problem. The SmtpClient.Send() method calls SmtpTransport.SendMail() to communicate with the SMTP server. Since the SMTP protocol requires that the RCPT TO: command have its email address parameter delimited with angle brackets, SmtpTransport.SendMail() calls the internal method MailAddress.GetSmtpAddress() to get the value to send to the SMTP server:
internal string GetSmtpAddress(bool allowUnicode)
{
return String.Format(CultureInfo.InvariantCulture, "<{0}>", GetAddress(allowUnicode));
}
But if the RCPT TO: command fails, then SmtpTransport.SendMail() populates the SmtpFailedRecipientException with this calculated "SMTP address", instead of the MailAddress.Address property!
Is this a bug-report-worthy problem?
EDIT Dec 15 2014
I opened Connect bug 970353 three months ago, and gave them code to reproduce the issue. No word yet.
Mail servers often present email addresses in this format to clients: "John Smith" <john.smith#domain.com>.
You should expect addresses of this format to maybe come back. You could try passing the string you receive to the System.Net.Mail.MailAddress class to parse it for you:
string emailAddress = new System.Net.Mail.MailAddress("\"John Smith\" <john.smith#domain.com>").Address;
There's further information on this class here.

Categories