2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MimeKitでメールアドレスが有効な形式か確認する

Posted at

はじめに

C#のメールアドレスの形式チェックは文字列が有効な電子メール形式であるかどうかを検証する方法をコピペで利用してきました。

MimeKitでメール送信機能を追加したとき、上記の形式チェックではアットマークの前にドットが含まれるメールアドレス xxxx.@xx.xx がエラーとならず、送信処理のタイミングでエラーとなってしまうため、メールアドレスのチェックもMimeKit側で行う暫定対応を行いました。

メール検証用のプログラム

 try
 {
     // メールアドレスチェック
     var kitMailAddress = new MimeKit.MailboxAddress(null, "xxxx.@xx.xx");
 }
 catch (Exception ex)
 {
     // xxxx.@xx.xxはエラーとなりExceptionに入る。
 }

本来であれば xxxx.@xx.xx というメールアドレスは有効であるため、送信対象としたいのですが、良い方法が見つからずSendGridへ移行する事になりました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?