How can I let the user email me through the game? Cocos2d-js

Hi!
I am fairly new to this and I am on my way to making my first mobile game!

I am just wondering if there is a simple way to let the user/player email directly to me at an email that I set.
So, in my mind, the user would touch a button on the main menu and it would open up the mailing app or something like that.
This way, it’ll simplify the bugreporting and suggestions.

Sample code in JS or resource links would be greatly helpful!!

Best regards, and thank you for any help you provide.

I have this piece of code in the main activity in the android project:
public static void EXT_shareText(String textToShare) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
sendIntent.setType(“text/plain”);
Cocos2dxActivity.getContext().startActivity(sendIntent);
}

And the js to call this:

jsb.reflection.callStaticMethod(“com/yourPacket/yourActivity”, EXT_ShareText, “(Ljava/lang/String;)V”, textToShare);

It’s not exactly what you want because this opens every app with a text but maybe it points you to what you want.

Use sendintent.setType("message/rfc822"); instead. It will display only e-mail applications.
Also add
sendIntent.addEmailTo("youremailid@gmail.com"); sendIntent.setSubject(activity.getString(R.string.app_name));

@fubit Or you could simply use the good old mailto with parameters. It would open the os default mail application and the user will send you the mail as usual. Sometimes best solutions are simple solutions.

You can specify the subject and even the body of the email:

https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MailLinks/MailLinks.html

2 Likes

@Eschmelax

Thank you! this seems like exactly what I need!
However, how would I go about implementing into the game? (I’m not sure as I am quite new to this and app/game development in general.)
As well, is there something similar to this on the Android and Windows platform? Or is it all universal?

The game will be hosted hopefully on iOS, Android and Windows, and I am not sure how to place in the JS mailto functionality without HTML. As far as I understand, Cocos2d JS requires no html for hosting on phone.

@i__d__k and @alexgg thanks for your input as well!

@fubit Yes, mailto is universal. Every device today has a mail application installed.
About implemetation in JS without a link, you could try:

window.location = 'mailto:this.that@here.com'; or
window.location.href = 'mailto:this.that@here.com';

This should go into your touchEvent or wherever you want to call it.

Here is mailto with parameters: mailto:user@user.com?subject=Subject&cc=CC&bcc=BCC&body=BODY.

Post back your results and good luck.
This shouldn’t be complicated.

@Eschmelax
Hi! I’ve been trying the method you outlined, and have been doing some research elsewhere, but to no avail.

I have placed the mailto thing in a button, as so:

var MailButton = new cc.MenuItemImage(
            res.MailButton_png,
            res.MailButtonPressed_png,
            function(){
                cc.log("mail button pressed");
                window.location.href = 'mailto:mailaddress@gmail.com';
            },this);

However, when I press the button. the Xcode console says that window.location is undefined.

Hi, I’ve been reading the suggestions posted on this thread and have tried getting the mail functionality to work myself. Does the xCode iOS simulator have the capability to open a mail application?

I was using:
window.location = ‘mailto:example@gmail.com’;
to try and get the simulator to open a mail application, but nothing happened.

Any help is appreciated,

Thanks.

@fubit, @calicorob Sorry for delay. But i’ve figured out, why it won’t work like that.
It seems that this call will only work from UIWebView on iOS devices:

Without UIWebView (as in case of Cocos2D-X), you will need some kind of mixin from Objective C or C++ after checking if (cc.sys.isNative):

- (IBAction)showEmail:(id)sender {

    // Email Subject    
    NSString *emailTitle = @"Test Email";

    // Email Content    
    NSString *messageBody = @"iOS email such wow!";

    // Address
    NSArray *toRecipents = [NSArray arrayWithObject:@"your@destination.com"];  

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];    
    mc.mailComposeDelegate = self;

    [mc setSubject:emailTitle];    
    [mc setMessageBody:messageBody isHTML:NO];    
    [mc setToRecipients:toRecipents];    

    // Present mail view controller on screen    
    [self presentViewController:mc animated:YES completion:NULL];   
}

Modify for your purposes, hope you get the idea.
You need to check for isNative then implement in XCode or VS.

I have the same issue/question. I have an email button like this

    // Email Button
    var emailButton = new ccui.Button();
    emailButton.loadTextures("email_n.png", "email_s.png", "", ccui.Widget.PLIST_TEXTURE);
    emailButton.setTouchEnabled(true);
    emailButton.addTouchEventListener(this.onEmail, this);
    this.addChild(emailButton);

And then when it is touched I want to do this:

// Email selected
onEmail: function (sender, type) {
    switch (type) {
    case ccui.Widget.TOUCH_BEGAN:
        break;
    case ccui.Widget.TOUCH_MOVED:
        break;
    case ccui.Widget.TOUCH_ENDED:
        cc.sys.href = 'mailto:email@gmail.com';
        // or windows.location.href = 'mailto:email@gmail.com';
        break;
    case ccui.Widget.TOUCH_CANCELLED:
        break;
    }
}

But it’s not working. This is new to me so I’ll try to follow this thread but I find it confusing.
Thanks in advance for any help.

I couldn’t get it working either.
If you’ve figured it out, please post it here!