teisipäev, 6. november 2018

Kuidas kontrollida, kas IP-aadress pole sattunud spämminimekirja

Üks võimalus kontrolida, mida e-maili server sinu IP-st arvab on teha telnet käsk
"telnet mail.neti.ee 25" ja vaadata, mis vastuseks tuleb

Lõppkasutajale võib teha ekraani peale nupu, kliki seda ja vaata mida kostab

byte[] bytes = new byte[2048];
// Connect the socket to the remote endpoint. Catch any errors.
try
{
                IPHostEntry ipHostInfo = Dns.GetHostEntry(this.LiteralEpostiServer.Text.Trim());
                IPAddress ipAddress = ipHostInfo.AddressList[0];
                Socket sende = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                sende.Connect(ipAddress, Convert.ToInt32(this.LiteralPort.Text.Trim()));
                this.CustomValidator2.ErrorMessage = String.Format("Socket connected to {0}", sende.RemoteEndPoint.ToString());
                this.CustomValidator2.IsValid = false;
                // Encode the data string into a byte array.
                byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");

                // Send the data through the socket.
                int bytesSent = sende.Send(msg);

                // Receive the response from the remote device.
                int bytesRec = sende.Receive(bytes);
                this.CustomValidator3.ErrorMessage = String.Format("Echoed test = {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec));
                this.CustomValidator3.IsValid = false;
                // Release the socket.
                sende.Shutdown(SocketShutdown.Both);
                sende.Close();
}
catch (ArgumentNullException ane)
{
                this.CustomValidator1.ErrorMessage = "ArgumentNullException: " + ane.ToString();
                this.CustomValidator1.IsValid = false;
}
catch (SocketException se)
{
                //Console.WriteLine("SocketException : {0}", se.ToString());
                this.CustomValidator1.ErrorMessage = "SocketException: " + se.ToString();
                this.CustomValidator1.IsValid = false;
}
catch (SystemException ex)
{
                this.CustomValidator1.ErrorMessage = ex.Message;
                this.CustomValidator1.IsValid = false;
}

Kui vaja lugeda SQL DBMail serveri profiilist andmed, siis selleks järgmine salvestatud protseduur, mis kasutab lõpuks msdb.dbo.sysmail_help_account_sp protseduuri

ALTER PROCEDURE [dbo].[E_POSTI_SERVER_PROFIILIST]
WITH EXECUTE AS 'DBO'
AS
BEGIN
SET NOCOUNT ON
DECLARE @mail_profiil VARCHAR(100), @accountID INT
SET @mail_profiil = ( SELECT MAX(string) FROM DBO.DB_DEFAULT_PARAMS_S('MAIL_SERVER_PROFILE') WHERE erro=0 )
DECLARE @profiil TABLE (profile_id int, profile_name sysname, account_id int, account_name sysname, sequence_number int)
INSERT INTO @profiil EXEC msdb.dbo.sysmail_help_profileaccount_sp @profile_name=@mail_profiil
SET @accountID=(SELECT TOP 1 account_id FROM @profiil)
--SELECT * FROM @profiil
EXEC msdb.dbo.sysmail_help_account_sp  @account_id = @accountID
END