SMTP, POP3 and IMAP

7

SMTP, POP3 and IMAP are TCP/IP protocols used for mail delivery. Email clients use POP3 and IMAP protocol to retrieve email from the server (incoming mail) over TCP/IP connection. Outgoing mail for both POP and IMAP clients uses the SMTP. Main difference between POP3 and IMAP is,

  • POP3 – Downloads email locally
  • IMAP – Mail is stored on the mail server

SMTP

Simple Mail Transfer Protocol (SMTP) servers handle the sending of your e mail messages to the Internet. The SMTP server handles outgoing e mail, and is used in conjunction with a POP3 or IMAP incoming e mail server.

POP3

Post Office Protocol 3 (POP3) servers hold incoming e mail messages until you check your e mail, at which point they’re transferred to your computer. POP3 is the most common account type for personal e mail. Messages are typically deleted from the server when you check your e mail.

IMAP

Internet Message Access Protocol (IMAP) servers let you work with e mail messages without downloading them to your computer first. You can preview, delete, and organize messages directly on the e mail server, and copies are stored on the server until you choose to delete them. IMAP is commonly used for business e mail accounts.

Default Ports

  • SMTP AUTH: Port 25 or 587 (some ISPs are blocking port 25)
  • SMTP StartTLS Port 587
  • SMTP SSL Port 465
  • POP Port 110
  • POP SSL Port 995
  • IMAP Port 143
  • IMAP SSL Port 993
  • IMAP StartTLS Port 143

The following list of SMTP, POP3, and IMAP server should help you if you don’t know what mail server you should use for your mail account.

  SMTP POP3 IMAP
Gmail smtp.gmail.com pop.gmail.com imap.gmail.com
  SSL Port 465 SSL Port 995 SSL Port 993
  StartTLS Port 587
TLS/SSL encryption required: yes
Please make sure, that POP3 access is enabled in the account settings. Login to your account and enable POP3. Please make sure, that IMAP access is enabled in the account settings. Login to your account and enable IMAP.
Outlook.com smtp.live.com pop3.live.com imap.mail.yahoo.com
  StartTLS Port 587 SSL Port 995 SSL Port 993
  TLS/SSL encryption required: yes TLS/SSL encryption required: yes  
Yahoo Mail smtp.mail.yahoo.com pop.mail.yahoo.com  
  SSL Port 465 SSL Port 995  
Yahoo Mail Plus plus.smtp.mail.yahoo.com plus.pop.mail.yahoo.com plus.imap.mail.yahoo.com
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo UK smtp.mail.yahoo.co.uk pop.mail.yahoo.co.uk imap.mail.yahoo.co.uk
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo Deutschland smtp.mail.yahoo.de pop.mail.yahoo.de imap.mail.yahoo.de
  SSL Port 465 SSL Port 995 SSL Port 993
Yahoo AU/NZ smtp.mail.yahoo.com.au pop.mail.yahoo.com.au imap.mail.yahoo.com.au
  SSL Port 465 SSL Port 995 SSL Port 993
Windows Live (Hotmail) smtp.live.com pop3.live.com  
  StartTLS Port 587 SSL Port 995  

JavaScript Frameworks and Resources

1

Knockout.js

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintainably.
http://knockoutjs.com/
Knockout.js

Angular.js

AngularJS is an open-source JavaScript framework, maintained by Google, that assists with running what are known as single-page applications. Its goal is to augment browser-based applications with model–view–controller (MVC) capability, in an effort to make both development and testing easier. The library reads in HTML that contains additional custom tag attributes; it then obeys the directives in those custom attributes, and binds input or output parts of the page to a model represented by standard JavaScript variables. The values of those JavaScript variables can be manually set, or retrieved from static or dynamic JSON resources.
http://angularjs.org/
Angular.js

Backbone.js

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
http://backbonejs.org
Backbone.js

Node.js

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
http://nodejs.org/
Node.js

Modernizr

Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications. Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is, very simply, tell you whether the current browser has this feature natively implemented or not.
http://modernizr.com
Modernizr

Require.js

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.
http://requirejs.org
Require.js

Less

LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
http://lesscss.org/
Less

Sass

Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
http://sass-lang.com
Saas

HTML5 Cheat Sheet

0

HTML5 Cheat Sheet – Tags

HTML5 Cheat Sheet - Tags

HTML5 Cheat Sheet By InMotion Hosting – A Virtual Private Servers Provider

HTML5 Cheat Sheet – Event Handler Attributes

HTML5 Cheat Sheet - Event Handler Attributes

HTML5 Cheat Sheet By InMotion Hosting – A Web Hosting Provider

HTML5 Cheat Sheet – Browser Support

HTML5 Cheat Sheet - Browser Support

HTML5 Cheat Sheet By InMotion Hosting – A Dedicated Server Provider

Online tools for troubleshooting web, SQL, XML and JSON

1

Have you ever wanted to troubleshoot someone else web page which contains the combination of JavaScript, CSS and HTML? Have you ever wanted to troubleshoot someone else SQL query without entering to the SQL server? Here are some useful online tool which make your life easier.

Following tools provide an online debugging environment for HTML, CSS and JavaScript.

1. jsFiddle

jsFiddle is the most popular JavaScript sandbox. It provides instantly ready coding environment for you to begin experimenting in as soon as the page loads.

http://jsfiddle.net/

JS Fiddle

2. JS Bin

JS Bin is another JavaScript sandbox. The design of this app is quite minimal and really allows you to focus on the code. By default, the page only shows the HTML and lives preview panes, but you can easily add JavaScript to that as well.

http://jsbin.com/

JS Bin

3. CSSDesk

CSSDesk is a CSS sandbox which allows you to put your HTML and CSS codes there and view the preview instantly. It is very useful for testing out codes before implementing them in your website permanently.

http://cssdesk.com/

CSS Desk

4. CodePen

CodePen is an app for sharing and playing around with front end code. It’s a site for building stuff from HTML, CSS and JavaScript.

http://codepen.io/pen/

Code Pen

Following tool can use for easy online testing and sharing of database problems and solutions.

1. SQL Fiddle

SQL Fiddle is a tool for easy online testing and sharing of database problems and their solutions. If you do not know SQL or basic database concepts, this site is not going to be very useful to you. However, if you are a database developer, there are a few different use-cases of SQL Fiddle intended for you:

  • You want help with a tricky query, and you’d like to post a question to a Q/A site
  • You want to compare and contrast SQL statements in different database back-ends
  • You do not have a particular database platform readily available, but you would like to see what a given query would look like in that environment

http://sqlfiddle.com/

SQL Fiddle

Following tools act as sandbox environment for JSON,  XML development, including (E)XSLT, XML validation (DTD, schema, RelaxNG) and XQuery.

1. XMLPlayground

XMLPlayground is a sandbox environment for XML development, including (E)XSLT, XML validation (DTD, schema, RelaxNG) and XQuery. It has five development panels into which you can either insert or upload code:

  • XML – your source XML. You can render it as a node tree via the ‘tree’ tab.
  • (E)XSLT – transform your XML with XSLT (1.0). EXSLT an XSL includes are supported.
  • Validation – validate your XML with Schema, DTD or RelaxNG.
  • CSS – style your output
  • XQuery – query or transform your XML with XQuery code (via XQIB)

http://xmlplayground.com/

XML Playground

2. JSON Fiddle

With JSON Fiddle, simulating and posting JSON in Fiddler is just as easy.

http://jsonfiddle.net

json fiddle

Counting Consecutive Dates Using SQL

1

Download demo query

Recently I have answered one of the SQL based question in the CodeProject. Thanks for the participant that question wake up me to write this blog post.

Question:

He has a table (tblLeave) with the data like below.

PAYCODE		LV_TYPE	FROM_DATE		TO_DATE	        	LVALUE
5023		SL    	14/12/2012 0:00		14/12/2012 0:00		1
5023		SL    	15/12/2012 0:00		15/12/2012 0:00		1
5023		COF   	16/12/2012 0:00		16/12/2012 0:00		1
5023		SL    	19/12/2012 0:00		19/12/2012 0:00		1
5023		SL    	22/12/2012 0:00		22/12/2012 0:00		1
5023		SL    	23/12/2012 0:00		23/12/2012 0:00		1
5023		SL    	24/12/2012 0:00		24/12/2012 0:00		1
5023		PL    	28/12/2012 0:00		28/12/2012 0:00		1
5023		PL    	29/12/2012 0:00		29/12/2012 0:00		1
5023		PL    	30/12/2012 0:00		30/12/2012 0:00		1
5023		PL    	31/12/2012 0:00		31/12/2012 0:00		1

And he wants to output the data as below

PAYCODE LV_TYPE FROM_DATE       TO_DATE         LVALUE
5023    SL      14/12/2012 0:00 15/12/2012 0:00 2
5023    COF     16/12/2012 0:00 16/12/2012 0:00 1
5023    SL      19/12/2012 0:00 19/12/2012 0:00 1
5023    SL      22/12/2012 0:00 24/12/2012 0:00 3
5023    PL      28/12/2012 0:00 31/12/2012 0:00 4

Condition: If same type of leave taken continuously, it should be merged in one row mentioning from_date to to_date.

Answer:

When I saw that question first time, I didn’t go through in details and just thought that was an easy grouping query. And I just gave following answer.

SELECT LV_TYPE,LV_TYPE,MIN(FROM_DATE) AS FROM_DATE ,MAX(TO_DATE) AS TO_DATE, COUNT(LVALUEP) AS LVALUE
FROM tblLeave
GROUP BY PAYCODE,LV_TYPE

But that’s wrong, he made comments saying it doesn’t make sense and highlighted the condition he wants. (Thanks for him; he didn’t down vote my answer). Again I read the question… Oh… That was a tricky question. He needs to group the leave by consecutive date. Isn’t that tricky?

To answer that, I use the DATEDIFF SQL function

DATEDIFF ( datepart , startdate , enddate )

http://msdn.microsoft.com/en-us/library/ms189794.aspx

Following is my answer and the output

SELECT PAYCODE,LV_TYPE, MIN(FROM_DATE) AS FROM_DATE,
       MAX(FROM_DATE) AS TO_DATE, COUNT('A') AS LVALUE
FROM (
SELECT PAYCODE,LV_TYPE,FROM_DATE,
    DATEDIFF(D, ROW_NUMBER() OVER(ORDER BY FROM_DATE), FROM_DATE) AS Diff
FROM tblLeave) AS dt
GROUP BY PAYCODE,LV_TYPE, Diff
ORDER BY FROM_DATE
PAYCODE     LV_TYPE FROM_DATE               TO_DATE                 LVALUE
----------- ------- ----------------------- ----------------------- -----------
5023        SL      2012-12-14 00:00:00.000 2012-12-15 00:00:00.000 2
5023        COF     2012-12-16 00:00:00.000 2012-12-16 00:00:00.000 1
5023        SL      2012-12-19 00:00:00.000 2012-12-19 00:00:00.000 1
5023        SL      2012-12-22 00:00:00.000 2012-12-24 00:00:00.000 3
5023        PL      2012-12-28 00:00:00.000 2012-12-31 00:00:00.000 4

Query Explanation:

Before explain the logic see the following query and the output.

SELECT PAYCODE,LV_TYPE,FROM_DATE,
	ROW_NUMBER() OVER(ORDER BY FROM_DATE) AS ROW_NUMBER,
    DATEDIFF(D, ROW_NUMBER() OVER(ORDER BY FROM_DATE), FROM_DATE) AS Diff
FROM tblLeave
PAYCODE     LV_TYPE FROM_DATE               ROW_NUMBER           Diff
----------- ------- ----------------------- -------------------- -----------
5023        SL      2012-12-14 00:00:00.000 1                    41254
5023        SL      2012-12-15 00:00:00.000 2                    41254
5023        COF     2012-12-16 00:00:00.000 3                    41254
5023        SL      2012-12-19 00:00:00.000 4                    41256
5023        SL      2012-12-22 00:00:00.000 5                    41258
5023        SL      2012-12-23 00:00:00.000 6                    41258
5023        SL      2012-12-24 00:00:00.000 7                    41258
5023        PL      2012-12-28 00:00:00.000 8                    41261
5023        PL      2012-12-29 00:00:00.000 9                    41261
5023        PL      2012-12-30 00:00:00.000 10                   41261
5023        PL      2012-12-31 00:00:00.000 11                   41261

By seen this, you will realize that above query generate the same Diff  value for all the consecutive dates. Now you can easily group this and get the counts as you like.

Generating and splitting a delimited string column

1

Download demo query – 1.6 KB

Introduction

Recently I have answered one of the Code Project questions, in brief the question was, how to split the delimited string and return as row values. This is one of the common questions we all are facing in our development. Not only splitting the delimited string, but also we struggle when creating the delimited strings using SQL.

In this article, I will show you how easily this can be done by using the SQL XQuery.

Creating delimited strings

Suppose we have a table called DeveloperProject to store the individual developer project list.

DECLARE @DeveloperProject Table(
 DeveoperID INT,
 ProjectCode VARCHAR(20)
)
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(1,'CODE_PROJECT')
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(1,'MSFT')
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(1,'REPT_MOD')
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(2,'MSFT')
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(2,'CODE_PROJECT')
INSERT INTO @DeveloperProject(DeveoperID, ProjectCode) VALUES(3,'REPT_MOD')

Now we need to convert this as follows

DeveoperID  ProjectCodes
----------- ------------------------
1           CODE_PROJECT,MSFT,REPT_MOD
2           MSFT,CODE_PROJECT
3           REPT_MOD

There are many ways to do this. But here is the easiest way.

SELECT DeveoperID,
    REPLACE((SELECT ProjectCode AS'data()'
        FROM @DeveloperProject dp2
        WHERE dp2.DeveoperID = dp1.DeveoperID
    FOR XML PATH('')),' ',',')AS ProjectCodes
FROM @DeveloperProject dp1
GROUP BY DeveoperID
Instead of REPLACE function you can also use the SUBSTRING function as below
SELECT DeveoperID,
    SUBSTRING((SELECT ','+ ProjectCode
        FROM @DeveloperProject dp2
        WHERE dp2.DeveoperID = dp1.DeveoperID
    FOR XML PATH('')), 2, 8000)AS ProjectCodes
FROM @DeveloperProject dp1
GROUP BY DeveoperID
Table with delimited column

FOR XML() clause

A SELECT query returns results as a rowset. You can optionally retrieve formal results of a SQL query as XML by specifying the FOR XML clause in the query.
http://msdn.microsoft.com/en-us/library/ms178107.aspx

data() function

If you want to get the value of an attribute, rather than the attribute node itself, we can use the data() method.

For ex: if you execute the following query, you will get the xml output with <ProjectCode> attribute nodes.

SELECT ProjectCode
FROM @DeveloperProject c2
FOR XML PATH('')

XML PATH with Nodes
Now run it as follows, and see the result set. It gives the output without <ProjectCode> nodes.

SELECT ProjectCode AS 'data()'
FROM @DeveloperProject c2
FOR XML PATH('')

XML PATH without Nodes

Splitting delimited string

Suppose we have a table called DeveloperProjectCSV to store the developer id and comma separated project list

DECLARE @DeveloperProjectCSV Table(
    DeveoperID INT,
    ProjectCodes  VARCHAR(MAX)
)

We can use previously created script to insert the data to this table.

INSERT INTO @DeveloperProjectCSV(DeveoperID,ProjectCodes)
SELECT DeveoperID,
    REPLACE((SELECT
        ProjectCode AS 'data()'
     FROM @DeveloperProject dp2
     WHERE dp2.DeveoperID = dp1.DeveoperID
     FOR XML PATH('')), ' ', ',') AS ProjectCodes
FROM @DeveloperProject dp1
GROUP BY DeveoperID

Now the table contains following data

DeveoperID  ProjectCodes
----------- ------------------------------
1           CODE_PROJECT,MSFT,REPT_MOD
2           MSFT,CODE_PROJECT
3           REPT_MOD

And we need to split the project codes for each developer.

;WITH cte AS (
    SELECT
        DeveoperID,
        CAST('' + REPLACE(ProjectCodes, ',', '') + '' AS XML) AS ProjectCodes
    FROM @DeveloperProjectCSV
)
SELECT
    DeveoperID,
    xTable.xColumn.value('.', 'VARCHAR(MAX)') AS ProjectCode
FROM cte
CROSS APPLY ProjectCodes.nodes('//r') AS xTable(xColumn)

Splited string

WITH (common_table_expression)

WITH is used to specify the temporary named result set. In above WITH block creates temporary results set with two columns. One is a DeveloperID and other one is an xml type column for ProjectCodes
http://msdn.microsoft.com/en-us/library/ms175972.aspx

nodes() Method

The nodes() method is useful when you want to share an xml data type instance into relational data. It allows you to identify nodes that will be mapped into a new row.

nodes (XQuery) as Table(Column)

http://msdn.microsoft.com/en-us/library/ms188282(v=sql.100).aspx

CROSS APPLY

CROSS APPLY is just like an inner join query clause which allows joining between two table expressions.
http://technet.microsoft.com/en-us/library/ms175156.aspx


Creating delimited strings with SQL 2000

Since SQL 2000 doesn’t support XML PATH, above query doesn’t work with SQL 2000. As an alternative option we can use COALESCE or ISNULL function and create User Defined Function to get the concatenation output.
Suppose we have a table called “DeveloperProject” with following data inserted.

DeveloperID ProjectCode
----------- --------------------
1           CODE_PROJECT
1           MSFT
1           REPT_MOD
2           MSFT
2           CODE_PROJECT
3           REPT_MOD

First we have to create the concatenation function

CREATE FUNCTION dbo.rowToCSV(@DeveoperID int )
RETURNS VARCHAR(MAX)
AS
BEGIN
    DECLARE @ProjectCodes VARCHAR(MAX)
    SELECT @ProjectCodes = COALESCE(@ProjectCodes + ', ', '') + ProjectCode
    FROM DeveloperProject
    WHERE DeveoperID = @DeveoperID
    RETURN @ProjectCodes
END

By using the above function, you will can get the same output.

SELECT
DeveoperID,
ProjectCodes = dbo.rowToCSV(DeveoperID )
FROM DeveloperProject
GROUP BY DeveoperID

Delimited String

COALESCE and ISNULL

COALESCE returns the first nonnull expression among its arguments. This is just like ISNULL function in SQL. Both ISNULL and COALESCE can be used to get the same results but there are some differences. http://msdn.microsoft.com/en-us/library/ms190349(v=sql.90).aspx

Splitting delimited string with SQL 2000
Again, SQL 2000 doesn’t support WITH (Common table expression) and the APPLY operators. As an alternative option we can use the spt_values master table.

SELECT  a.DeveloperID,
SUBSTRING(',' + a.ProjectCodes + ',', n.Number + 1, CHARINDEX(',', ',' + a.ProjectCodes + ',', n.Number + 1) - n.Number - 1) AS [Value]
FROM DeveloperProjects AS a
INNER JOIN master..spt_values AS n ON SUBSTRING(',' + a.ProjectCodes + ',', n.Number, 1) = ','
WHERE n.Type = 'p'
    AND n.Number > 0
    AND n.Number < LEN(',' + a.ProjectCodes + ',')

spt_values

spt_values is an undocumented system table, which contains various data items used by Microsoft written stored procedures. We can use the rows with type = ‘P’ to have a numbers table with the numbers from 1-2047.