Archive for December, 2017

#Verify an #Email Address with a #DNS #MX lookup in C#

December 11, 2017 Leave a comment


Sending an email to an invalid email address has some bad side effects, the most important being, is that your message is not going through to its intended recipient, and on a larger scale, a bad email counts towards your bounce ratio with your SMTP provider, which in extreme cases can cause legal issues with EU PECR laws.

You can always, verify the format of an email address using a regex, but this has two issues – one, is that new TLD’s like “.museum” or “.家電” might break the regex, and secondly, even if the email is valid. Secondly, some domains are valid, but have no MX record set up to handle email. like “” is going to pass any regex, but “” has no ability to handle email.

So, here’s a bit of code in C# that verifies the domain part of the email;

public static bool VerifyEmailDomain(string domain)
// Install-Package ARSoft.Tools.Net
var resolver = new DnsStubResolver();
var records = resolver.Resolve<MxRecord>(domain, RecordType.Mx);
return records.Any();
catch {
return false;

Now, unfortunately, it’s not possible to check if is valid, even if using this technique, however, if it is really important, then you can check gmail accounts against the API – to verify if the Gmail account has a profile attached.

This technique is the basis behind – a email sending API that bypasses intermediary SMTP servers.


Categories: Uncategorized

Send a message with #PushBullet using c#

December 7, 2017 Leave a comment


Pushbullet is an iOS / Android and Web based app, that is used for automated messaging. It’s pretty easy to use from within C#, here’s an example;

* curl –header ‘Access-Token: <your_access_token_here>’ \
–header ‘Content-Type: application/json’ \
–data-binary ‘{“body”:”Space Elevator, Mars Hyperloop, Space Model S (Model Space?)”,”title”:”Space Travel Ideas”,”type”:”note”}’ \
–request POST \

var message = new
body = “Space Elevator, Mars Hyperloop, Space Model S (Model Space?)”,
title = “Space Travel Ideas”,
type = “note”
WebClient wc = new WebClient();
wc.Headers[“Access-Token”] = “o.xxxxxxxxxxxxxx”;
wc.Headers[“Content-Type”] = “application/json”;
var strPayload = JsonConvert.SerializeObject(message);
var strResponse = wc.UploadString(“;, strPayload);

“active”: true,
“iden”: “xxxxxxx”,
“created”: 1512656152.566,
“modified”: 1512656152.5928,
“type”: “note”,
“dismissed”: false,
“direction”: “self”,
“sender_iden”: “ujvhvGp18iy”,
“sender_email”: “”,
“sender_email_normalized”: “”,
“sender_name”: “xxxx xxxx”,
“receiver_iden”: “ujvhvGp18iy”,
“receiver_email”: “”,
“receiver_email_normalized”: “”,
“title”: “Space Travel Ideas”,
“body”: “Space Elevator, Mars Hyperloop, Space Model S (Model Space?)”

The above code requires the NUNIT package Install-Package Newtonsoft.Json, and you’ll need an access token from pushbullet under your account > Settings


Categories: Uncategorized

#Bitcoin clipboard #Virus, and how to avoid it.

December 6, 2017 Leave a comment


When checking stats on – all of the Bitcoin Millionaires (> USD$ 1M) on the site shared the same Bitcoin wallet 13JF5274VuNthhwKkLrYyZW73smjSYAEen

This turned out to be something very sinister indeed. 

A windows Virus, called Trojan.Coinbitclip – watches your windows clipboard for a Bitcoin wallet address, then when detected, replaces it with the hacker’s account. meaning, if you are about to make a bitcoin payment, you end up giving it to the hacker, rather than the person you intended to pay.

To avoid it, you should always copy and paste into notepad, compare the numbers, and if they are not identical, then run a full virus scan on your computer. Bitcoin addresses are designed not to look visually identical, so it should be easy to spot.

Here is some further reading on the subject:

Categories: Uncategorized

Creating a #Facebook #Chatbot using #AWS #Lex and #Lambda

December 6, 2017 Leave a comment


Chatbots are a novel way of interacting with your customers if you don’t have the staff to deal with them personally.

Creating one using Amazon LEX is really easy, and you can do it with no code whatsoever. – Although if you want it to do anything of use, then you’ll need to write a Lambda function.

First, log into AWS, open up LEX, then create a new Bot.

You’ll need to set up an Intent, and add an utterance that will activate this intent. You add slots – which are dynamic data provided by the user that provides you with the information you need to fulfil the user’s request.

You can test it out on the right hand side of the page, but the real kicker is getting the bot to work with Facebook. – So, you head on over to and create a new App. Select Products > Add product > Messenger

In Token Generation, select your Facebook Page, and press generate. You’ll need this token later.  – Also grab the app secret key, you’ll need this in a moment.

Head back over to LEX, select Channels, then fill in the form, – Your Verify Token can be anything at all, just remember it for the next step.  Press activate, and you’ll get an Endpoint URL.

Jump back to Facebook, and open up the webhooks tab.  Create a new webhook, and enter the Verify Token, and the Endpoint URL. give permissions for the following: messages, messaging_postbacks, messaging_optins , and then select a page, and press subscribe to events.

Now, if you open Facebook messenger on your phone and start a chat with your business page, your bot should start replying to messages

Of course, to make it do anything useful, you have to write some code, To do this, you create a lambda function in AWS, and link it to the Fulfilment step in LEX. In this example, I am taking the data provided by the user, and building up a URL from it, that the user can click – so that a web-page can finish serving the customer.

I used this code; based on the orderFlowers NodeJs example.

function elicitSlot(sessionAttributes, intentName, slots, slotToElicit, message) {
return {
dialogAction: {
type: ‘ElicitSlot’,

function close(sessionAttributes, fulfillmentState, message, responseCard) {
return {
dialogAction: {
type: ‘Close’,

function delegate(sessionAttributes, slots) {
return {
dialogAction: {
type: ‘Delegate’,

function FindFlight(intentRequest, callback) {
const source = intentRequest.invocationSource;
const depart = intentRequest.currentIntent.slots.departure;
const destination = intentRequest.currentIntent.slots.destination;
const departureDate = intentRequest.currentIntent.slots.departureDate;
const returnDate = intentRequest.currentIntent.slots.returnDate;
const Adults = intentRequest.currentIntent.slots.Adults;
const Children = intentRequest.currentIntent.slots.Children;
const infants = intentRequest.currentIntent.slots.infants;

if (source === ‘DialogCodeHook’) {
const outputSessionAttributes = intentRequest.sessionAttributes;
callback(delegate(outputSessionAttributes, intentRequest.currentIntent.slots));
callback(close(intentRequest.sessionAttributes, ‘Fulfilled’,
contentType: ‘PlainText’,
content: `Click the following link to see our flight offers`
“version”: 3,
“contentType”: “application/vnd.amazonaws.card.generic”,
“genericAttachments”: [
“title”:`${depart} to ${destination}`,
“subTitle”:`${departureDate} – ${returnDate}`,



* Called when the user specifies an intent for this skill.
function dispatch(intentRequest, callback) {
console.log(`dispatch userId=${intentRequest.userId}, intentName=${}`);

const intentName =;

// Dispatch to your skill’s intent handlers
if (intentName === ‘YOUR-INTENT’) {
return FindFlight(intentRequest, callback);
throw new Error(`Intent with name ${intentName} not supported`);


exports.handler = (event, context, callback) => {
// TODO implement
dispatch(event, (response) => callback(null, response));


Categories: Uncategorized