158 lines
5.7 KiB
C#
158 lines
5.7 KiB
C#
using MailKit.Net.Smtp;
|
|
using MailKit.Security;
|
|
using MimeKit;
|
|
using Mono.Addins;
|
|
using Nini.Config;
|
|
using OpenMetaverse;
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
using OpenSim.Region.Framework.Scenes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
[assembly: Addin("MailKitMailModule", "0.1")]
|
|
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
|
|
namespace OpenSim.Modules.EMail
|
|
{
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MailKitMailModule")]
|
|
class MailKitMailModule : INonSharedRegionModule, IEmailModule
|
|
{
|
|
private IConfigSource m_config = null;
|
|
private bool m_enabled = false;
|
|
|
|
private Scene m_scene = null;
|
|
|
|
private String SMTP_SERVER_HOSTNAME = null;
|
|
private String SMTP_SERVER_LOGIN = null;
|
|
private String SMTP_SERVER_PASSWORD = null;
|
|
private String SMTP_SERVER_SENDER = null;
|
|
private int SMTP_SERVER_PORT = 25;
|
|
private bool SMTP_SERVER_SSL = false;
|
|
private bool SMTP_SERVER_TLS = false;
|
|
|
|
private String IMAP_SERVER_HOSTNAME = null;
|
|
private String IMAP_SERVER_LOGIN = null;
|
|
private String IMAP_SERVER_PASSWORD = null;
|
|
private int IMAP_SERVER_PORT = 25;
|
|
private bool IMAP_SERVER_SSL = false;
|
|
private bool IMAP_SERVER_TLS = false;
|
|
|
|
#region ISharedRegionModule
|
|
public string Name
|
|
{
|
|
get { return "MailKitMailModule"; }
|
|
}
|
|
|
|
public Type ReplaceableInterface
|
|
{
|
|
get { return null; }
|
|
}
|
|
|
|
public void AddRegion(Scene scene)
|
|
{
|
|
if (!m_enabled)
|
|
return;
|
|
|
|
scene.RegisterModuleInterface<IEmailModule>(this);
|
|
m_scene = scene;
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Initialise(IConfigSource source)
|
|
{
|
|
m_config = source;
|
|
|
|
if(source.Configs["Startup"] != null)
|
|
{
|
|
m_enabled = (m_config.Configs["Startup"].GetString("emailmodule", "DefaultEmailModule") == "MailKitMailModule");
|
|
|
|
if (!m_enabled)
|
|
return;
|
|
}
|
|
|
|
if (source.Configs["Mail"] == null)
|
|
return;
|
|
|
|
SMTP_SERVER_HOSTNAME = m_config.Configs["Mail"].GetString("SMTP_SERVER_HOSTNAME", String.Empty);
|
|
SMTP_SERVER_PORT = m_config.Configs["Mail"].GetInt("SMTP_SERVER_PORT", 25);
|
|
SMTP_SERVER_SSL = m_config.Configs["Mail"].GetBoolean("SMTP_SERVER_SSL", false);
|
|
SMTP_SERVER_TLS = m_config.Configs["Mail"].GetBoolean("SMTP_SERVER_TLS", false);
|
|
SMTP_SERVER_LOGIN = m_config.Configs["Mail"].GetString("SMTP_SERVER_LOGIN", String.Empty);
|
|
SMTP_SERVER_PASSWORD = m_config.Configs["Mail"].GetString("SMTP_SERVER_PASSWORD", String.Empty);
|
|
SMTP_SERVER_SENDER = m_config.Configs["Mail"].GetString("SMTP_SERVER_SENDER", "");
|
|
|
|
IMAP_SERVER_HOSTNAME = m_config.Configs["Mail"].GetString("IMAP_SERVER_HOSTNAME", String.Empty);
|
|
IMAP_SERVER_PORT = m_config.Configs["Mail"].GetInt("IMAP_SERVER_PORT", 25);
|
|
IMAP_SERVER_SSL = m_config.Configs["Mail"].GetBoolean("IMAP_SERVER_SSL", false);
|
|
IMAP_SERVER_TLS = m_config.Configs["Mail"].GetBoolean("IMAP_SERVER_TLS", false);
|
|
IMAP_SERVER_LOGIN = m_config.Configs["Mail"].GetString("IMAP_SERVER_LOGIN", String.Empty);
|
|
IMAP_SERVER_PASSWORD = m_config.Configs["Mail"].GetString("IMAP_SERVER_PASSWORD", String.Empty);
|
|
}
|
|
|
|
public void PostInitialise()
|
|
{
|
|
}
|
|
|
|
public void RegionLoaded(Scene scene)
|
|
{
|
|
}
|
|
|
|
public void RemoveRegion(Scene scene)
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
|
|
public void SendEmail(UUID objectID, string address, string subject, string body)
|
|
{
|
|
SceneObjectPart sceneObject = m_scene.GetSceneObjectPart(objectID);
|
|
|
|
MimeMessage message = new MimeMessage();
|
|
message.From.Add(new MailboxAddress(sceneObject.Name, sceneObject.UUID + "@" + SMTP_SERVER_SENDER));
|
|
message.To.Add(new MailboxAddress("", address));
|
|
message.Subject = subject;
|
|
message.Body = new TextPart("plain"){Text = body};
|
|
|
|
message.Headers.Add(new Header(Encoding.UTF8, "ObjectID", sceneObject.UUID.ToString()));
|
|
message.Headers.Add(new Header(Encoding.UTF8, "AvatarID", sceneObject.OwnerID.ToString()));
|
|
message.Headers.Add(new Header(Encoding.UTF8, "Location", m_scene.Name + "@" + sceneObject.GetWorldPosition().ToString()));
|
|
|
|
using (var client = new SmtpClient())
|
|
{
|
|
client.CheckCertificateRevocation = false;
|
|
|
|
if (SMTP_SERVER_SSL == true)
|
|
{
|
|
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.Auto);
|
|
}
|
|
else if(SMTP_SERVER_TLS == true)
|
|
{
|
|
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.StartTlsWhenAvailable);
|
|
}
|
|
else
|
|
{
|
|
client.Connect(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT, SecureSocketOptions.None);
|
|
}
|
|
|
|
if(SMTP_SERVER_LOGIN != String.Empty && SMTP_SERVER_PASSWORD != String.Empty)
|
|
client.Authenticate(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);
|
|
|
|
client.Send(message);
|
|
client.Disconnect(true);
|
|
}
|
|
}
|
|
|
|
public Email GetNextEmail(UUID objectID, string sender, string subject)
|
|
{
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|