Link Search Menu Expand Document

QR Code with Email - C#

BarCode SDK sample in C# demonstrating ‘QR Code with Email’

Program.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

using Bytescout.BarCode;
using CreateBarCode;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create new barcode
            Barcode barcode = new Barcode();

            // Set symbology
            barcode.Symbology = SymbologyType.QRCode;

            // Inputs
            var inpEmail = new QrCodeEmailTemplate
            {
                Email = "sample@email.com",
                Subject = "Hello There!",
                Message = "Sample message goes here..."
            };

            // Set value            
            barcode.Value = inpEmail.ToString();

            // Save barcode to image
            barcode.SaveImage("result.png");

            // Show image in default image viewer
            Process.Start("result.png");
        }
    }
}

QrCodeEmailTemplate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CreateBarCode
{
    class QrCodeEmailTemplate
    {
        #region Constructors

        public QrCodeEmailTemplate() { }
        public QrCodeEmailTemplate(string Email, string Subject, string Message)
        {
            this.Email = Email;
            this.Subject = Subject;
            this.Message = Message;
        }

        #endregion

        #region Properties

        public string Email { get; set; }
        public string Subject { get; set; }
        public string Message { get; set; }

        #endregion

        #region Overloaded Methods

        public override string ToString()
        {
            if (string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Subject) && string.IsNullOrEmpty(Message))
                return base.ToString();

            return $@"MATMSG:TO:

{Email};

SUB:

{Subject}

BODY:

{Message}
;;";
        }

        #endregion
    }
}

Download Source Code (.zip)

Return to the previous page Explore BarCode SDK