Smtpコンポーネントを使用して、添付ファイルの付いたテキストメッセージを送信します。
private void sendMail(object sender)
{
// 送信するメッセージを作成します。
MailMessage message = new MailMessage();
message.To = toAddress;
message.From = fromAddress;
message.Subject = "File Attached";
message.Text = "Please see the attached file.";
// 添付ファイルを追加します。
message.Attachments.Add(new Attachment(Application.StartupPath + "\\myImage.jpg"));
// セッションパラメーターを設定します。
smtp1.Session.RemoteEndPoint =
new Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session));
smtp1.Session.Username = myUsername;
smtp1.Session.Password = myPassword;
// メッセージを送信します。
smtp1.Send(message);
// 適切にログアウトします。
smtp1.Close();
}
private void smtp1_Progress(object sender, SmtpProgressEventArgs e)
{
// メッセージの送信状況に従ってプログレスバーを更新します。
progressBar1.Value = (e.Final) ? 0 : (int)((e.Position * 100) / e.Length);
}
Private Sub sendMail(ByVal sender As Object)
' 送信するメソッドを作成します。
Dim message As New MailMessage()
message.To = toAddress
message.From = fromAddress
message.Subject = "File Attached"
message.Text = "Please see the attached file."
' 添付ファイルを追加します。
message.Attachments.Add(New Attachment(Application.StartupPath & "\myImage.jpg"))
' セッションパラメーターを設定します。
smtp1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session))
smtp1.Session.Username = myUsername
smtp1.Session.Password = myPassword
' メッセージを送信します。
smtp1.Send(message)
' 適切にログアウトします。
smtp1.Close()
End Sub
Private Sub smtp1_Progress(ByVal sender As Object, ByVal e As SmtpProgressEventArgs) Handles smtp1.Progress
' メッセージの送信状況に従ってプログレスバーを更新します。
progressBar1.Value = If(e.Final, 0, CInt((e.Position * 100) \ e.Length))
End Sub