[SOLVED] Creating Ticket via email

Moderator: crythias

Locked
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

[SOLVED] Creating Ticket via email

Post by jeremyk »

Ok So I have finally been able to create a web form using HTML/PHP and the OTRS Generic Interface. The issue that I am now facing is that when I use the TicketCreate method, it creates my ticket no problem, I can set dynamic fields and all that works.

HOWEVER, for the value of "CustomerUser" if I do not put in an existing registrered Customer or Agents email address in, it does not set anything for CustomerID and I can only see who the ticket came from based on the "From" field.


I am using this as a web form on our support website so that customers can hit our website and submit a ticket into our system. If they are forced to have a registered customer account in our OTRS already, it defeats the purpose of the web form. If they are already registered, they can just log into the Customer Portal and place a ticket that way.

I need to figure out how I can set the value of CustomerUser and or CustomerID to an email address that does not already exist in the database.

Previously using rpc.pl, I was able to do this no problem. No matter if the customer existed or not, whatever I passed in for CustomerUser, got set as the CustomerID and showed in my TicketOverview. Digging into the TicketCreate.pm in opt/otrs/Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm it looks as if the customerUser does not exist, it will set it, but that does not seem to be working.

I would like to figure out how to regain that same functionality using the Generic Interface. Here is the code that I am using:

Code: Select all

<?php
if (isset($_POST["emailAddr"])) {

$url = 'http://otrs.xxxxxx.com/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector';
$username = 'xxxxxxxxx';
$password = 'xxxxxxxxx';

//# Set up a new SOAP connection:
try {
   $client = new SoapClient(null, array('location'  => $url,
                                        'uri'       => 'ticketconnector:actions',      // make sure it's the same as the namespace in network config of the webservice
                                        'trace'     => true,
                                        'style'     => SOAP_RPC,
                                        'use'       => SOAP_ENCODED));
} catch (Exception $e) {
   echo "<h2>Exception Error!</h2>";
   echo $e->getMessage();
}

var_dump($client);

$Operation = 'TicketCreate';

try {
   $TicketID = $client->__soapCall($Operation, array(

      new SoapParam($username, "UserLogin"),
      new SoapParam($password, "Password"),

      new SoapParam(array(
         "Title" => $_POST["subject"],
         "CustomerUser" => $_POST["emailAddr"],      // this one must exist as a customer but I need it to accept it whether it is a user or not. 
	     "CustomerID" => $_POST["emailAddr"],
         "Queue" => "Support",
         "State" => "new",
         "PriorityID" => 3,
         "Type" => "default"
      ), "Ticket"),

      new SoapParam(array(
         "Subject" => $_POST["subject"],
         "Body" => $_POST["description"],
         "ContentType" => 'text/html; charset=utf8'
      ), "Article") ,
      
      new SoapParam(array(
         "Name" => "company",
         "Value" => $_POST["company"]
      ), "DynamicField")
   ));
} catch (SoapFault $fault) {
   echo "REQUEST:\n".$client->__getLastRequest()."\n";
   echo "RESPONSE:\n".$client->__getLastResponse()."\n";
   echo "</pre>";
   exit;
}
var_dump($TicketID);

}

?>
Last edited by jeremyk on 16 Aug 2013, 16:03, edited 2 times in total.
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Use GenericInterface TicketCreate with non existing cust

Post by crythias »

jeremyk wrote:I am using this as a web form on our support website so that customers can hit our website and submit a ticket into our system. If they are forced to have a registered customer account in our OTRS already, it defeats the purpose of the web form.
Do you allow anonymous (unauthenticated) submissions on your support website, or do your customers have to log into that?
If so, you might want to consider using your support's website authenticatication as pass through to OTRS.

If not,
The TicketCreate method assumes a CustomerLogin exists on submit. Email/Postmaster that split this out if doesn't exist, but the GenericInterface assumes that tickets are being created with real users.

If you submitted this ticket via email, you wouldn't have this problem, and you could use X-OTRS-headers to pass variables.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

Our support site does not require a log in for authentication. We are using a valid user for soap authentication to be able to create the ticket, but this is not the same account as the person placing the ticket.

The reason we shy'd away from the email was because I was not sure how I could pass dynamic variables through the email. I like the idea of the webservice better (especially because I spent a week trying to get it to work), but I do not understand why it requires an existing customer to be the one placing a ticket, and why this didnt happen when using RPC.pl.

Are the two ticketcreate methods different (from what rpc.pl calls and what generic interface calls)?


If I am going to be forced to use email only to submit tickets, can you please explain or point me in the right direction of how to properly use the XOTRS headers to pull a value out of the email and put it into a dynamic field?

I really appreciate the help.

Thanks,

Jeremy
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

upon submit via email, include in the headers X-OTRS-DynamicField-yourfieldname: yourvalue
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:upon submit via email, include in the headers X-OTRS-DynamicField-yourfieldname: yourvalue

The problem is though, that my value is dynamic, based on input from the person submitting the ticket.

Is there some way for me to be able to tag that value with something and pull it in from the submittal? That is why we have been trying to figure out the webservice, so that I can have dynamic fields set based on input from the user.
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

jeremyk wrote:The problem is though, that my value is dynamic, based on input from the person submitting the ticket.
I'm assuming the value is as dynamic as the email address and body and yet you probably know how to handle that. Same thing. This is a header, like "To:" or "From:"
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

also, the email needs to be trusted to receive OTRS headers (Admin, Email settings).
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

So in the Value field in the Email filter rule (shown here:
set header.JPG
)

, I can put in a header, rather than a static Value?
You do not have the required permissions to view the files attached to this post.
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

no. you can ignore this and post the values in the sent email.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:no. you can ignore this and post the values in the sent email.

Alright so now I am using

Code: Select all






<?php

if (isset($_POST["emailAddr"])){

$company = $_POST["company"];
$emailAddy = $_POST["emailAddr"];

//define the receiver of the email
$to = 'jeremyk@xxxxxx.com';
//define the subject of the email
$subject = $_POST["subject"];
//define the message to be sent. Each line should be separated with \n
$message = $_POST["description"];
//define the headers we want passed. Note that they are separated with \r\n
$headers = "FROM: $emailAddy\r\nReply-To: $emailAddy\r\nX-OTRS-DynamicField-company: $company";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
echo $_POST["company"];
echo $_POST["emailAddr"];
echo $company;
echo $emailAddy;

}
?>

</body>
</html>
This properly generated my ticket with the companyID set as I would like it, however my dynamic field is not getting set.

I sent one to myself so I could look at the headers, and this is what I am seeing:
Received: from mail.xxxx.com (192.168.10.1) by mail.xxxxx.com
(192.168.10.100) with Microsoft SMTP Server id 8.1.436.0; Thu, 1 Aug 2013
15:06:47 -0400
Received: from ip-10-13-31-20.ec2.internal [xx.xx.xx.xx] by
dmtmg.xxxx.COM;Thu, 1 Aug 2013 15:06:45 -0400
Received: by ip-10-13-31-20.ec2.internal (Postfix, from userid 33) id
D69C4218A7; Thu, 1 Aug 2013 15:00:00 -0400 (EDT)
To: jeremyk@xxxxx.com
Subject: test to myself
X-PHP-Originating-Script: 0:formEmail.php
From: <jeremy@xxxxx.com>
Reply-To: jeremy@xxxxxx.com
X-OTRS-DynamicField-company: xxxxxxx
Message-ID: <20130801190000.D69C4218A7@ip-xx-xx-xx-xx.ec2.internal>
Date: Thu, 1 Aug 2013 15:00:00 -0400
MIME-Version: 1.0
Content-Type: text/plain
Return-Path: www-data@otrs.xxxxxx.com



Is there anything special i need to be doing with setting that header. It is definitely getting the value, but it is not setting anything.
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

Make sure the email is trusted in Admin Email configuration
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:Make sure the email is trusted in Admin Email configuration

Yeah I had originally forgot about that part, but I have since gone back and changed that.

I get my From: header getting set, however my X-OTRS-DynamicField-company: is not getting set. As mentioned before, if I send it to my own email address and investigate the headers, I see that it is properly showing the value set for that header.

Could it be a syntax issue? I have been messing around with it a lot (syntax wise) but I cannot get it to set the dynamic field. Are there other headers that must be set as well to be able to make this work?

This is my PHP for sending the email

Code: Select all

<?php

if (isset($_POST["emailAddr"])){

$company = $_POST["company"];
$emailAddy = $_POST["emailAddr"];

//define the receiver of the email
$to = 'otrs@xxxxxxx.com';
//define the subject of the email
$subject = $_POST["subject"];
//define the message to be sent. Each line should be separated with \n
$message = $_POST["description"];
//define the headers we want passed. Note that they are separated with \r\n
$headers = 'X-OTRS-DynamicField-company: '.$company."\r\n".'From: '.$emailAddy."\r\n".phpversion();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

}
?>
Does anything look wrong to you?
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

Syntax, perhaps .. case, spelling of field ... If it's a dropdown, you want the left side, instead of display value.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:Syntax, perhaps .. case, spelling of field ... If it's a dropdown, you want the left side, instead of display value.

I am happy to finally be able to respond.

Anyway, I believe I have checked all the syntax and all of that looks good. When I analyze the email that is being generated, I see the header in there with its value. I also tried this with Thunderbird, manually adding the headers into the emails and sending them, and OTRS still is not reading those X headers.

I even tried to use one of the built in ones like X-OTRS-Priority, and I cannot get OTRS to read that.

I know the emails being sent have the headers, its just almost as if the email address is not trusted, even though that setting it set in the Postmaster Email Addresses.

Is there anything else you can think of that may be causing this issue for me. It seems like every time I try a different method of getting this to work, one thing works, but then another thing doesnt. I am still pretty shocked that I cannot use a non existing customer when using the web service, but either way I have built an entire form around email. I just need to figure out now, why OTRS is not reading the X headers.

Any suggestions are greatly appreciated.

Thanks
OTRS v3.2.8 running on Debian 7 with MySQL
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:Syntax, perhaps .. case, spelling of field ... If it's a dropdown, you want the left side, instead of display value.
Any suggestions on this? Unfortunately I am still stuck on the same issue. I cannot get OTRS to read the X headers on an email sent to one of my postmaster addresses, even though that address is set as Trusted.

Thanks
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

Please edit your signature, let us know what version you're using, sample header data, screenshots of confirmation of what you think it should be, etc.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:Please edit your signature, let us know what version you're using, sample header data, screenshots of confirmation of what you think it should be, etc.

This is part of the code that I am currently using to generate the email from my PHP webform.

Code: Select all

                // Headers
                $headers = "From: $email_from";

                // create a boundary string. It must be unique
                  $semi_rand = md5(time());
                  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

                  // Add the headers for a file attachment
                  $headers .= "\nX-OTRS-DynamicField-company:$company\n" .
                                          "MIME-Version: 1.0\n" .
                              "Content-Type: multipart/mixed;\n" .
                              " boundary=\"{$mime_boundary}\"";

                  // Add a multipart boundary above the plain message
                  $message ="This is a multi-part message in MIME format.\n\n";
                  $message.="--{$mime_boundary}\n";
                  $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
                  $message.="Content-Transfer-Encoding: 7bit\n\n";
                  $message.=$ticketmessage."\n\n";
                  $message.=$description."\n\n";

                if (is_uploaded_file($fileatt)) {
                  // Read the file to be attached ('rb' = read binary)
                  $file = fopen($fileatt,'rb');
                  $data = fread($file,filesize($fileatt));
                  fclose($file);

                  // Base64 encode the file data
                  $data = chunk_split(base64_encode($data));

                  // Add file attachment to the message
                  $message .= "--{$mime_boundary}\n" .
                              "Content-Type: {$fileatt_type};\n" .
                              " name=\"{$fileatt_name}\"\n" .
                              //"Content-Disposition: attachment;\n" .
                              //" filename=\"{$fileatt_name}\"\n" .
                              "Content-Transfer-Encoding: base64\n\n" .
                              $data . "\n\n" .
                              "--{$mime_boundary}--\n";
                }


                if(!mail($email_to,$email_subject,$message,$headers)) {
                        exit("Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");
                } else {
                        echo '<div id="formfeedback"><h3>Thank You!</h3><p>'. $thanksmessage .'</p></div>';
                        //unset($_SESSION['myForm']);
                        //print_form();

                } // end of if !mail


Here are part of the headers of the email that is being sent:

To: jeremyk@xxxxxxx.com
Subject: This is a test Ticket
X-PHP-Originating-Script: 0:webForm.php
From: <test@test.com>
X-OTRS-DynamicField-company: Test Company
MIME-Version: 1.0

It seems that even though it is adding the header X-OTRS-DynamicField-company with the value of Test Company, but OTRS is not reading that X header.

Here is the config page for my postmaster address:
postmaster.JPG

Is there any other possible setting that must be set. Does the dynamic field x header need to be added into Core::Postmaster in sysconfig?


Any other info you need?
You do not have the required permissions to view the files attached to this post.
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

To: jeremyk@xxxxxxx.com
This is the email address that is set as "trust"?
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

crythias wrote:To: jeremyk@xxxxxxx.com
This is the email address that is set as "trust"?

No the webforms@ address is. I changed it for an example so I could send it to myself so I could explore the headers. Typically that To: field is set to webforms@xxxx.com
OTRS v3.2.8 running on Debian 7 with MySQL
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: GenericInterface TicketCreate with non existing customer

Post by crythias »

Check if:
DynamicField is Ticket
case is the same for the fieldname
DynamicField is enabled/valid
Header is X-OTRS-DynamicField-DynamicFieldID

Set $Self->{Debug} = 1 in Config.pm
Look for $Key: xxx in logs

Check if multi-word value makes sense for your pass-through. (maybe "Test Company" ?
Determine if you really want to pass X-OTRS-DynamicField-company instead of
X-OTRS-CustomerNo: emailaddress or companyshortcode
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
jeremyk
Znuny newbie
Posts: 21
Joined: 18 Jul 2013, 15:29
Znuny Version: 3.2.8
Real Name: Jeremy Kessous
Company: DataMotion

Re: GenericInterface TicketCreate with non existing customer

Post by jeremyk »

Ahh this is resolved, it probably was actually working all along, but our exchange server, or a mail gateway we have seemed to be stripping off internet headers, so my X-OTRS-DynamicField header was never making it once it was popped to otrs. I created a gmail account and I am now using that and it is working just fine.

Thank you for your help.
OTRS v3.2.8 running on Debian 7 with MySQL
Locked