Thursday, December 24, 2015

JavaScript - Simple Email without any server code

I have thought of using simple JavaScript Email feature using "mailTo:". But this is not used for bigger body contents or if you planned for much styles.

Use below JavaScript Method to send emails.

You can use more URL encode to format body.

Ref for URL Encode:  http://www.w3schools.com/tags/ref_urlencode.asp
For MailTo Documentation:  http://www.ietf.org/rfc/rfc2368.txt

JavaScript:

function SendEmail() {

   var subject = 'Mail subject goes here..';
   var body = 'Hi,%0D%0A %0D%0A' +
            'Some of your content %0D%0A%0D%0A' +
            'Next line of body goes here.%0D%0A' +
            '%E2%80%A2 Text within Bullet Text here %E2%80%A2 %0D%0A' +
           
            '%0D%0A Thanks & Regards,%0D%0A' +
            'Your signature goes here..';


    window.location = 'mailto:?subject=' + subject + '&body=' + body;

    return false;

};

HTML:

<input type="button" value="Email" onclick="SendEmail();"/>

Friday, December 11, 2015

CSS - How to make two divs in equal height within container without any script

To set two divs to equal height dynamically without any scripts use this code  

<div class="equal-height-container">
            <div class="equal-height-box">
                dynamic content goes here..
            </div>
            <div class ="equal-height-box">
                dynamic content goes here..
            </div>

   </div>



.equal-height-container {
    display: table;
}

.equal-height-box {
    display: table-cell;
    height: auto;
    overflow: hidden;
    float:none;
    vertical-align:top;
}

Monday, December 7, 2015

C# - How to send email without any plugins


Below code helps to send email without any third party email plugins, but it requires SMTPServer details to be specified in web.config AppSettings. That server needs to be configured as email server.

using System.Net.Mail;
public void SendEmail(string fromAddress, string[] toAddress, string subject, string bodyContent, string[] filenames)
        {
            MailMessage email = new MailMessage();

            email.From = new MailAddress(fromAddress);
            if (toAddress != null && toAddress.Length > 0)
            {
                foreach (var toAdd in toAddress)
                {
                    email.To.Add(new MailAddress(toAdd));
                }
            }

            email.Subject = subject;
            email.Body = bodyContent;

            if (filenames != null && filenames.Length > 0)
            {
                foreach (var file in filenames)
                {
                    Attachment attachment;
                    attachment = new Attachment(@file);
                    email.Attachments.Add(attachment);
                }
            }

            try
            {
                using (var client = new SmtpClient())
                {
                    client.Send(email);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                email.Dispose();
            };
        }