Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
SmtpClient, change authentication type of credential
using (var client = new SmtpClient())
{
    client.UseDefaultCredentials = false;
    client.Host = setting.Host;
    client.Port = setting.Port;
    client.EnableSsl = setting.EnableSsl;

    CredentialCache cache = new CredentialCache();
    // authentication type:  gssapi, ntlm, WDigest, login
    cache.Add(setting.Host, setting.Port, "login", new NetworkCredential(setting.UserName, setting.Password));
    client.Credentials = cache;

    using (var message = new MailMessage())
    {
        var body = System.IO.File.ReadAllText("content.email");

        message.From = new MailAddress(setting.Sender);
        message.ReplyToList.Add(new MailAddress(setting.Email));
        message.To.Add(new MailAddress(setting.Receiver));
        message.IsBodyHtml = true;
        message.Body = body;
        message.Subject = setting.Subject;
        message.BodyEncoding = Encoding.UTF8;
        message.SubjectEncoding = Encoding.UTF8;

        try { client.Send(message); }
        catch (Exception ex)
        {
            Log.Write(ex);
        }
    }
}
Zxing: generate QR code
var code = "Hello, QRCode";
var hints = new Dictionary();
hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.Add(EncodeHintType.MARGIN, 2);

var qrWriter = new QRCodeWriter();
var result = qrWriter.encode(code, BarcodeFormat.QR_CODE, 200, 200, hints);

var writer = new BarcodeWriter() { Format = BarcodeFormat.QR_CODE };
var bitmap = writer.Write(result);

var ms = new System.IO.MemoryStream();
var img = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Close();

System.IO.File.WriteAllBytes("qrcode.png", ms.ToArray());