Send email using bu...
 
Notifications
Clear all

Send email using build in mailer

3 Posts
2 Users
0 Reactions
883 Views
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

Hello, Dear Skared Creations!

I have a question, is it possible to use build in mailer to send email from withing the app? I d like to implement feedback solution to let user to send message not leaving the application.

Thanks.

PS beta 8 works perfect so far 🙂

 
Posted : 18/03/2017 10:25 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

It's pretty easy to implement:

1. Create the a PHP file called send_email.php in the root of Combu folder on your web server with this code:

<?php
include_once 'lib/api.php';

use CombuMail;
use CombuUtils;
use CombuErrorMessage;
define("SEND_EMAIL_TO", "you_email@your_server.com");
$success = FALSE;
$message = "";

if (empty($WS_REQUEST) || !$LoggedAccount->IsLogged()) {
   // Unauthorized request
   $message = ErrorMessage::Get(ERROR_UNAUTHORIZED_REQUEST);
} else {
   // Get email data from request data
   $subject = $WS_REQUEST["subject"];
   $body = $WS_REQUEST["body"];
   // Send email
   $mail = new Mail();
   $mail->prepare($subject, $body, SEND_EMAIL_TO, $LoggedAccount->Email, $LoggedAccount->Username);
   $success = $mail->Send();
   $message = $mail->ErrorInfo;
}

Utils::EchoJson(Utils::JsonEncodeSuccessMessage($success, $message));

2. then call this web service in Unity:

var form = CombuManager.instance.CreateForm();
form.AddField("subject", "Email test");
form.AddField("body", "This is a test message");
CombuManager.instance.CallWebservice(CombuManager.instance.GetUrl("send_email.php"), form, (string text, string error) => {
   bool success = false;
   if (string.IsNullOrEmpty(error))
   {
      Hashtable result = text.hashtableFromJson();
      if (result != null)
      {
         if (result.ContainsKey("success"))
         bool.TryParse(result["success"].ToString(), out success);
         if (!success && result.ContainsKey("message"))
            error = result["message"].ToString();
      }
   }
   Debug.Log("Send Email: Success=" + success + " --- Error=" + error);
});

The code above is for Combu 3.0 and assumes that your user is already authenticated.

 

...or you could use our add-on Issue Tracker for Combu that allows you to handle issue feedbacks and attaches output logs (the one you see on Console log in Unity) and screenshot. Though we didn't release a version compatible with Combu 3 for our add-ons, we have already implemented but will release when Combu 3 will be finally released to the public. 🙂

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 18/03/2017 12:18 pm
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

Thanks a lot! Very easy to implement! Gonna use this until 3.0 addons will be relesed.

 
Posted : 18/03/2017 1:37 pm
Share: