- Home /
Send HTML email from iOS app
Im using the following script which works fine on iOS:
using UnityEngine;
using System.Collections;
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class mono_gmail : MonoBehaviour {
void Main ()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("youraddress@gmail.com");
mail.To.Add("youraddress@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("youraddress@gmail.com", "yourpassword") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
Debug.Log("success");
}
}
However, the client wants to be able to insert a HTML coded email that will have branding, social media links etc.
Is there any way I can incorporate that into this?
Answer by T27M · Mar 08, 2019 at 12:52 PM
I would probably recommend using a 3rd party service to send these emails out. Ideally you would want to separate the "send an email" aspect from the email content. The application logic would trigger the email to be sent (via an API call for example) with some information e.g a static email template name like "WelcomeEmail".
Then the email content can be defined elsewhere, even by the client themselves. This makes it a bit more flexible in the future and removes the need to update the code to change the email content. A service I have used in the past is SendGrid, but I'm sure there are many more you could use.
Your answer
Follow this Question
Related Questions
Send HTML email to native email client 3 Answers
get information from external application 1 Answer
Web based AR app 9 Answers
swiftUI build problem,swiftUI 0 Answers
Can't send email from ios device when email body contains arabic characters! 2 Answers