Configuring Email in SQL Server Express

Its a known issue that SQL Server express edition wont support Email . TO overcome this we can use CLR based email stored procedure.   Step 1 : Compile the VB code and convert as a dll. Code : Imports System.Net.Mail Public Class StoredProcedure <Microsoft.SqlServer.Server.SqlProcedure()> _ Public Shared Sub spSendMail(ByVal recipients As String, ByVal subject As String, ByVal from As String, ByVal body As String) Dim mySmtpClient As SmtpClient Using myMessage As New MailMessage(from, recipients) myMessage.Subject = subject myMessage.Body = body myMessage.IsBodyHtml = True mySmtpClient = New SmtpClient(“smtp.zxvzxvxzvx.com”) mySmtpClient.Credentials = New System.Net.NetworkCredential(“haneef@xcxzvcxzvz.com”, “vzxvxzvxzvz”) mySmtpClient.Send(myMessage) End Using End Sub End Class Step 2: Replace these 2 lines with your smtp username , password amd smtp server adress mySmtpClient = New SmtpClient(“smtpxxxxxxxx.com”) mySmtpClient.Credentials = New System.Net.NetworkCredential(“haneef@xxxxxxxx.com”, “Password”) Save the above file in d:\sendmail.vb Step 3: Complie the code using below command.   C:\Windows\system32>C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc /target:li brary D:\sendmail.vb The above will comile and create a file sendmail.dll in the same location. Step 4: Run this command in SQL management studio ALTER DATABASE msdb SET trustworthy ON Step 5: Create the assembly in SQL management studio   USE msdb GO CREATE ASSEMBLY SendEmail FROM ‘C:\SendEmail.dll’ WITH PERMISSION_SET = UNSAFE GO Step 6: Enable CLR sp_configure […]

» Read more

Running Image Service from PHP

Scenario : Imagine that you want to run an image service and your clients will use these images in their static site developments. The moment you change these in the server it automatically reflect in the client designs. This is a POC design and can be used in KIOSKS, Web designs etc. Basically wherever you need the dynamic image you will use image src as a php destination. <img src=”http://servername.com/image.php” /> Whenever the server receives the request it will serves the image whichever is assigned to that. Concept: <?php header(“Content-type: text/xml”); $txt=”http://www.haneefputtur/xyx/138778535913.jpg”; $image=imagecreatefromjpeg($txt); imagejpeg($image); imagedestroy($image); ?> If you wish to make it dynamic then store the image data in a mysql database. Then select the image randomly or by sending query parameter so that you will get dynamic images.   Hereis the sample codes to get and display data from mysql database   <?php $servername = “localhost”; $username = “xxxxxxx”; $password = “xxxx”; $dbname = “haneee_2015”;   // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die(“Connection failed: ” . $conn->connect_error); }   $sql = “SELECT img_name FROM hanee_2015.tbl_banners WHERE active=1 AND img_name LIKE ‘%.jpg%’ LIMIT “.$_GET[“img”].”, 1;”; $result = $conn->query($sql);     […]

» Read more