Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pkg/connectors/Email/commands/admin/testsmtp.src
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
Use uo;
use uo;
use os;
use cfgfile;
use file;

include ":email:emailer";

program textcmd_testsmtp(who)

var toAddress := RequestInput(who, who.backpack, "Enter email address:" );
var outbound := SendEmail( toAddress, "Test Email from UO Server", "Test was successful");

if(outbound == error)
SendsysMessage( who, outbound.errortext );
endif
program textcmd_testsmtp( who )

var toAddress := RequestInput( who, who.backpack, "Enter email address:" );
var outbound := SendEmailDeprecated( toAddress, "Test Email from UO Server",
"Test was successful" );

if ( outbound == error )
SendsysMessage( who, outbound.errortext );
endif

endprogram

endprogram
208 changes: 113 additions & 95 deletions pkg/connectors/Email/include/emailer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Purpose
* Provide a single function to be able to quickly send email from within the server without external programs.
* (Excluding an SMTP server)
*
*
* Created by Dev GIB
*
*/
use uo;
use os;


/*
* SendEmail( ToAddress, Subject, Body, Modifiers)
* SendEmailDeprecated( ToAddress, Subject, Body, Modifiers)
*
* Deprecated: use os::SendEmail
* Purpose
* Sends an email to address or addresses based on information given to the function.
* Multiple emails can be defined for any given email field, its important to seperate with a semicolon
Expand All @@ -35,70 +35,81 @@ use os;
* Failure - Returns error message.
*
*/
function SendEmail( ToEmail, Subject, Body, Modifiers:=0)

var settings_cfg := ReadConfigFile(":emailer:settings");
if( settings_cfg.errortext )
SysLog("Error::SendEmail() - Unable to open [:emailer:settings.cfg] ->"+settings_cfg.errortext);
return error{"errortext" := "Unable to open [:emailer:settings.cfg]"};
endif

var cfg_elem := FindConfigElem( settings_cfg, "Settings" );

var smtpHost := GetConfigString( cfg_elem, "host" );
var LoggingLevel := cInt(GetConfigString( cfg_elem, "LoggingLevel" ));
if( LoggingLevel == error )
LogToFile("::log/emailer.log", "Error::SendEmail() - Logging level config not found or incorrect.", LOG_DATETIME);
endif
if( smtpHost == error )
if( LoggingLevel >= 1 )
LogToFile("::log/emailer.log", "Error::SendEmail() - SMTP host config not found or incorrect.", LOG_DATETIME);
endif
return error{"errortext" := "SMTP host config not found or incorrect."};
endif
var smtpPort := GetConfigString( cfg_elem, "port" );
if( smtpPort == error )
if( LoggingLevel >= 1 )
LogToFile("::log/emailer.log", "Error::SendEmail() - SMTP port config not found or incorrect.", LOG_DATETIME);
endif
return error{"errortext" := "SMTP port config not found or incorrect."};
endif

if( !Modifiers )
Modifiers := struct{};
Modifiers.FromEmail := "";
Modifiers.ToContactName := "";
Modifiers.CC := "";
Modifiers.BCC := "";
Modifiers.ReplyTo := "";
endif

if( !Modifiers.FromEmail )
Modifiers.FromEmail := GetConfigString( cfg_elem, "FromEmail" );//Sets the FromEmail to the default FromEmail in the config file.
endif


if( ValidateEmail( ToEmail ) != 1 )
if( LoggingLevel >= 1 )
LogToFile("::log/emailer.log", "Error::SendEmail() - ToEmail is not valid: "+ToEmail, LOG_DATETIME);
endif
return error{"errortext":="ToEmail is not valid."};
endif
if( ValidateEmail( Modifiers.FromEmail ) != 1 )
if( LoggingLevel >= 1 )
LogToFile("::log/emailer.log", "Error::SendEmail() - Modifiers.FromEmail is not valid: "+Modifiers.FromEmail, LOG_DATETIME);
endif
return error{"errortext":="FromAddress is not valid."};
endif

var EmailCommand := BuildEmailStruct( ToEmail, Subject, Body, Modifiers );
if( LoggingLevel > 0 ) EmailCommand.LL := LoggingLevel; endif
var connection := OpenConnection( smtpHost, cint(smtpPort), ":emailer:sendEmail", EmailCommand, 1 );
if( connection == error )
return connection;
endif
return 1;

function SendEmailDeprecated( ToEmail, Subject, Body, Modifiers := 0 )

var settings_cfg := ReadConfigFile( ":emailer:settings" );
if ( settings_cfg.errortext )
SysLog( "Error::SendEmail() - Unable to open [:emailer:settings.cfg] ->" + settings_cfg.errortext );
return error{ "errortext" := "Unable to open [:emailer:settings.cfg]" };
endif

var cfg_elem := FindConfigElem( settings_cfg, "Settings" );

var smtpHost := GetConfigString( cfg_elem, "host" );
var LoggingLevel := cInt( GetConfigString( cfg_elem, "LoggingLevel" ) );
if ( LoggingLevel == error )
LogToFile( "::log/emailer.log",
"Error::SendEmail() - Logging level config not found or incorrect.",
LOG_DATETIME );
endif
if ( smtpHost == error )
if ( LoggingLevel >= 1 )
LogToFile( "::log/emailer.log",
"Error::SendEmail() - SMTP host config not found or incorrect.",
LOG_DATETIME );
endif
return error{ "errortext" := "SMTP host config not found or incorrect." };
endif
var smtpPort := GetConfigString( cfg_elem, "port" );
if ( smtpPort == error )
if ( LoggingLevel >= 1 )
LogToFile( "::log/emailer.log",
"Error::SendEmail() - SMTP port config not found or incorrect.",
LOG_DATETIME );
endif
return error{ "errortext" := "SMTP port config not found or incorrect." };
endif

if ( !Modifiers )
Modifiers := struct{};
Modifiers.FromEmail := "";
Modifiers.ToContactName := "";
Modifiers.CC := "";
Modifiers.BCC := "";
Modifiers.ReplyTo := "";
endif

if ( !Modifiers.FromEmail )
Modifiers.FromEmail := GetConfigString( cfg_elem, "FromEmail" ); // Sets the FromEmail to the default FromEmail in the config file.
endif

if ( ValidateEmail( ToEmail ) != 1 )
if ( LoggingLevel >= 1 )
LogToFile( "::log/emailer.log", "Error::SendEmail() - ToEmail is not valid: "
+ ToEmail, LOG_DATETIME );
endif
return error{ "errortext" := "ToEmail is not valid." };
endif
if ( ValidateEmail( Modifiers.FromEmail ) != 1 )
if ( LoggingLevel >= 1 )
LogToFile( "::log/emailer.log",
"Error::SendEmail() - Modifiers.FromEmail is not valid: "
+ Modifiers.FromEmail, LOG_DATETIME );
endif
return error{ "errortext" := "FromAddress is not valid." };
endif

var EmailCommand := BuildEmailStruct( ToEmail, Subject, Body, Modifiers );
if ( LoggingLevel > 0 )
EmailCommand.LL := LoggingLevel;
endif
var connection := OpenConnection( smtpHost, cint( smtpPort ),
":emailer:sendEmail", EmailCommand, 1 );
if ( connection == error )
return connection;
endif
return 1;

endfunction

/*
Expand All @@ -121,23 +132,21 @@ function ValidateEmail( Address )
var HasAtSymbol := 0;
var HasFullStop := 0;
var i;

for ( i:= 1; i< address.length(); i:=i+1)
if( HasAtSymbol == 1 && HasFullStop == 1 )
return 1;

for ( i := 1; i < address.length(); i := i + 1 )
if ( HasAtSymbol == 1 && HasFullStop == 1 )
return 1;
endif
if ( address[i] == "@" )
HasAtSymbol := 1;
elseif ( address[i] == "." )
HasFullStop := 1;
endif
if ( address[i] == "@" )
HasAtSymbol := 1;
elseif( address[i] == "." );
HasFullStop := 1;
endif
endfor

return 0;

endfunction

return 0;

endfunction

/*
* BuildEmailStruct( ToEmail, Subject, Body, Modifiers )
Expand All @@ -164,18 +173,27 @@ endfunction
*/

function BuildEmailStruct( ToEmail, Subject, Body, Modifiers )

var TempStruct := struct{};

TempStruct.ToEmail := ToEmail;
TempStruct.Subject := Subject;
TempStruct.Body := Body;
TempStruct.FromEmail := Modifiers.FromEmail;
if( Modifiers.ToContactName ) TempStruct.ToContactName := Modifiers.ToContactName; endif
if( Modifiers.CC ) TempStruct.CC := Modifiers.CC; endif
if( Modifiers.BCC ) TempStruct.BCC := Modifiers.BCC;endif
if( Modifiers.ReplyTo ) TempStruct.ReplyTo := Modifiers.ReplyTo; endif

return TempStruct;

endfunction

var TempStruct := struct{};

TempStruct.ToEmail := ToEmail;
TempStruct.Subject := Subject;
TempStruct.Body := Body;
TempStruct.FromEmail := Modifiers.FromEmail;
if ( Modifiers.ToContactName )
TempStruct.ToContactName := Modifiers.ToContactName;
endif
if ( Modifiers.CC )
TempStruct.CC := Modifiers.CC;
endif
if ( Modifiers.BCC )
TempStruct.BCC := Modifiers.BCC;
endif
if ( Modifiers.ReplyTo )
TempStruct.ReplyTo := Modifiers.ReplyTo;
endif

return TempStruct;

endfunction

13 changes: 6 additions & 7 deletions scripts/include/sysEvent.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
//


// format-off
const SYSEVENT_SPEECH := 0x00000001;

const SYSEVENT_ENGAGED := 0x00000002;
Expand All @@ -22,8 +22,6 @@ const SYSEVENT_DAMAGED := 0x00000008;
const SYSEVENT_ENTEREDAREA := 0x00000010;
const SYSEVENT_LEFTAREA := 0x00000020;

const SYSEVENT_GONE_CRIMINAL := 0x2000;

const SYSEVENT_OPPONENT_MOVED := 0x00000040;

const SYSEVENT_HOSTILE_MOVED := 0x00000080; // not implemented
Expand All @@ -36,12 +34,12 @@ const SYSEVENT_ITEM_GIVEN := 0x00000400;
const SYSEVENT_DOUBLECLICKED := 0x00000800;

const SYSEVENT_GHOST_SPEECH := 0x00001000;
const SYSEVENT_RESERVED_00002000 := 0x00002000;
const SYSEVENT_TOKEN_SPEECH := 0x00004000;
const SYSEVENT_GONE_CRIMINAL := 0x00002000;
const SYSEVENT_TOKEN_SPEECH := 0x00004000;
const SYSEVENT_TOKEN_GHOST_SPEECH := 0x00008000;
const SYSEVENT_BOAT_MOVEMENT := 0x00010000;
const SYSEVENT_GUMP_RESPONSE := 0x00020000;

const SYSEVENT_RESERVED_00010000 := 0x00010000;
const SYSEVENT_RESERVED_00020000 := 0x00020000;
const SYSEVENT_RESERVED_00040000 := 0x00040000;
const SYSEVENT_RESERVED_00080000 := 0x00080000;
const SYSEVENT_RESERVED_00100000 := 0x00100000;
Expand All @@ -56,3 +54,4 @@ const SYSEVENT_RESERVED_10000000 := 0x10000000;
const SYSEVENT_RESERVED_20000000 := 0x20000000;
const SYSEVENT_RESERVED_40000000 := 0x40000000;
const SYSEVENT_RESERVED_80000000 := 0x80000000;

Loading