Hi guys !!! 8)
I wrote this class that works perfectly in Windows but that give me lots of problems with Unity:
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.Sockets;
using UnityEngine;
public class MailSender : MonoBehavior {
// Send an e-mail by using mono C# native classes using an existent Gmail account
// The "String file" parameter must contain the "filepath + nomefile" informations
public void sendReport (string file) {
try {
// Create the e-mail object
MailMessage msgMail = new MailMessage ("addressFrom@gmail.com", "addressTo@domain.ext", "Subject", "Body of the mail");
// Create the file attachment for this e-mail message.
Attachment att = new Attachment (file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = att.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime (file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime (file);
disposition.ReadDate = System.IO.File.GetLastAccessTime (file);
// Add the file attachment to this e-mail message.
msgMail.Attachments.Add (att);
// We need to use the port number 587 to send
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
// We neeed to enable the SSL encryption
smtp.EnableSsl = true;
// Set the delivery method to send directly with the exixtent connection via smtp
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
// disable the default credentials to make our own authentication
smtp.UseDefaultCredentials = false;
// set needed authentication parameters
smtp.Credentials = new System.Net.NetworkCredential ("username", "password");
smtp.Send (msgMail);
// Dispose the attachment
att.Dispose ();
} catch (Exception e) {
Debug.LogError (e.StackTrace);
} // try-catch
} // sendReport
} // MailSender
I think that, as it was written, couldn’t work with the mono version included in the current Unity 2.1 version.
Can anyone help me adapting this class to make possible to use it in Unity?
THANKS A LOT !!!