How to Fix Email Sending Issues in My iOS Unity App

I’m working on a school project using Unity and recently ran into a super frustrating problem: my app was supposed to send an email with some gameplay data, and everything worked perfectly in the Unity Editor. But as soon as I built it for iOS and ran it through Xcode on a real device boom, cryptic error, email failed, nothing worked.

So, if you’ve also tried to send an email from a Unity iOS unity app and faced a MissingMethodException, stick around. I’ll walk you through exactly what went wrong, show you the code that caused the issue, and explain how I worked around it. Plus, I’ll add a neat little improvement that logs gameplay data and lets the user send it via email in a more iOS friendly way.

Reproducing the Problem

Here’s the original code I used in Unity. I wanted the game to send an email with some basic data at runtime:

using System.Net.Mail;
using UnityEngine;

public class MonoGmail : MonoBehaviour
{
void Start()
{
SendEmail();
}

void SendEmail()
{
MailMessage mail = new MailMessage("from@example.com", "to@example.com");
SmtpClient smtpServer = new SmtpClient("smtp.example.com");

mail.Subject = "Game Data";
mail.Body = "Here is the game log data...";

smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("username", "password") as System.Net.ICredentialsByHost;
smtpServer.EnableSsl = true;

smtpServer.Send(mail);
Debug.Log("Email sent.");
}
}

This worked on my computer during tests, but once I built the app for iOS and launched it through Xcode, I saw this:

MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Net.Configuration.MailSettingsSectionGroup'

What Went Wrong

That error looked confusing at first, but after some digging, I found the cause.

Here the problem:

Unity uses IL2CPP to build for iOS. This means your C# code is converted to C++ ahead of time (AOT compilation). Some parts of .NET especially System.Net.Mail, SmtpClient, and System.Configuration aren’t compatible with IL2CPP and aren’t included in the runtime. So the app crashes at runtime when it tries to access them.

This is not a bug in your code. It’s just a limitation of the platform you’re building for.

The Fix Use mailto: for iOS Compatibility

Since we can’t use SmtpClient on iOS, the easiest workaround is to open the native email client with a pre-filled message using a mailto: URL. Here’s how I did it:

using UnityEngine;

public class EmailHandler : MonoBehaviour
{
public void SendLogByEmail()
{
string subject = EscapeURL("Game Log Data");
string body = EscapeURL("Here is the game log data: \n" + Application.persistentDataPath + "/log.txt");
string email = "recipient@example.com";

Application.OpenURL("mailto:" + email + "?subject=" + subject + "&body=" + body);
}

string EscapeURL(string url)
{
return WWW.EscapeURL(url).Replace("+", "%20");
}
}

Important Note:

This does not send the email automatically. It opens the user’s default email app (like Mail on iOS), and the user has to press Send manually. But that’s actually great for privacy and platform compliance.

Bonus Functionality Attach a Log File

I wanted to let players send their log data easily. Here’s how I wrote the game log to a file:

Save Log Data

void WriteGameLog(string data)
{
string path = Application.persistentDataPath + "/log.txt";
System.IO.File.WriteAllText(path, data);
}

Add a UI Button to Trigger Email

using UnityEngine;
using UnityEngine.UI;

public class EmailUI : MonoBehaviour
{
public Button sendButton;
private EmailHandler emailHandler = new EmailHandler();

void Start()
{
sendButton.onClick.AddListener(() => {
WriteGameLog("Score: 12345\nLevel: 5\nTime: 02:13");
emailHandler.SendLogByEmail();
});
}

void WriteGameLog(string data)
{
string path = Application.persistentDataPath + "/log.txt";
System.IO.File.WriteAllText(path, data);
}
}

This gives the user a button they can press to send their gameplay log to you via email. It’s simple, effective, and platform-safe.

Why Not Just Attach the File

Sadly, iOS doesn’t support file attachments with mailto: links. If you really want to include attachments, you’ll need:

  • A native iOS plugin (UniMail)
  • Or a backend server that handles the actual email sending via API (like Firebase, Node.js, or PHP backend).

Summary What’s the Best Option

FeatureSmtpClient (Not iOS Safe)mailto: (iOS Safe)
Automatically sends emailYesNo (user must send)
Can attach filesYesNo (iOS doesn’t support it)
Works with Unity iOS (IL2CPP)NoYes
Requires additional server/pluginNoNo (basic usage)
Privacy-friendlyCould leak credentialsYes (user-managed)

Pro Tip Platform Specific Code

If you’re building for multiple platforms (Android, iOS, PC), you can split the logic like this:

#if UNITY_IOS
Application.OpenURL(...); // Use mailto
#else
SendViaSMTP(); // For platforms that support it
#endif

Final Thought

So if you’re trying to send emails from your Unity app on iOS don’t fight the IL2CPP limitations. Just embrace the native mailto: functionality, which keeps your code clean, simple, and platform compliant. For more advanced use cases like attachments or automated reports, I’d recommend integrating with a backend service or using a native plugin built for Unity.

Related blog posts