UTF8メール送信ライブラリを作って go get 出来るようにしてみた

純正のAPIのnet/smtpはASCIIのメールを送るには問題ないのですが
日本語のメールを送る際に困るのでUTF8形式で
日本語メールを送れるライブラリを作ってみました。


今回テストはgospelを使って書いてみました。
Go言語の理解がまだまだなのでもっと良く出来る部分はあるかと思います。


GitHub - bose999/GoSendMail: simple smtp sendmail tool
Githubに置いてあります。


下記のような感じでUTF8で日本語メール等が送れます。

// smtpServer info : IP Address, port, userName, Password
smtpServer := gosendmail.NewSmtpSever("xxx.xxx.xxx.xxx", 25, "yyy", "zzz")

// sendmail info : from address, to address, cc address, subject, body
sendMail := gosendmail.NewSendMail("abc@xxx.xxx", []string{"abc@xxx.xxx"},
  []string{"xyz@gxxx.xxx"}, "UTF8のSubject", "UTF8の本文")

// send smtp mail
err := gosendmail.SendSmtp(smtpServer, sendMail)
if err != nil {
    log.Fatal(err)
     os.Exit(1)
}


Githubにおけば

% go get github.com/bose999/gosendmail

これでネットワークが繋がってればライブラリを
GOPATH配下に引き取れます。便利ですね!


このライブラリも業務で使おうかなと思って作ったものなので
必要があれば更新したり別のものも作ったりとしていこうと思います。

goclipseでGo言語をデバッグできるようにしてみる

まずgdbを入れます。

% brew install homebrew/dupes/gdb
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-dupes'...
remote: Counting objects: 1498, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 1498 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1498/1498), 299.62 KiB | 191.00 KiB/s, done.
Resolving deltas: 100% (823/823), done.
Checking connectivity... done.
Tapped 36 formulae
==> Installing gdb from homebrew/homebrew-dupes
==> Installing dependencies for gdb: xz, readline
==> Installing gdb dependency: xz
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/xz-5.0.7.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.0.7.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/xz/5.0.7: 58 files, 1.5M
==> Installing gdb dependency: readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.3.8.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.3.8.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
🍺  /usr/local/Cellar/readline/6.3.8: 40 files, 2.1M
==> Installing gdb
==> Downloading http://ftpmirror.gnu.org/gdb/gdb-7.8.1.tar.xz
######################################################################## 100.0%
==> Patching
patching file gdb/darwin-nat.c
==> ./configure --prefix=/usr/local/Cellar/gdb/7.8.1 --with-system-readline --with-lzma --with-python=/usr
==> make
==> make install
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  http://sourceware.org/gdb/wiki/BuildingOnDarwin
==> Summary
🍺  /usr/local/Cellar/gdb/7.8.1: 42 files, 5.7M, built in 11.1 minutes


これだけでは動かないので下記のページを参考に証明書処理の
手順1〜7を実行します。8はVerが違っちゃっていたので
※有効期間はめんどいので3650日にしてみました。
Safx: MacでGoのデバッグ環境を構築する


証明書の残りの処理をします。

% codesign -s gdb-cert /usr/local/Cellar/gdb/7.8.1/bin/gdb
% sudo killall taskgated
Password:


次に設定を変更します。

% sudo vi /System/Library/LaunchDaemons/com.apple.taskgated.plist
Password:

-s -> -spが変更点です。


Eclipse側にGDBを設定するとデバッグが可能になります。