'Variable which will send the mail
Dim obj As System.Net.Mail.SmtpClient
'Variable to store the attachments
Dim Attachment As System.Net.Mail.Attachment
'Variable to create the message to send
Dim Mailmsg As New Mail.MailMessage()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ol As New Outlook.Application()
Dim ns As Outlook.NameSpace
Dim fdMail As Outlook.MAPIFolder
ns = ol.GetNamespace("MAPI")
ns.Logon(, , True, True)
'creating a new MailItem object
Dim newMail As Outlook.MailItem
'gets defaultfolder for my Outlook Outbox
fdMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
'assign values to the newMail MailItem
newMail = fdMail.Items.Add(Outlook.OlItemType.olMailItem)
newMail.Subject = "tesst"
newMail.Body = "test"
newMail.To = TextBox1.Text
Dim sSource As String = Application.StartupPath + "\kk.sys"
' TODO: Replace with attachment name
Dim sDisplayName As String = "kaar.jpg"
Dim sBodyLen As String = newMail.Body.Length
newMail.SaveSentMessageFolder = fdMail
newMail.Send()
Catch ex As Exception
Using writer As StreamWriter = New StreamWriter(Application.StartupPath + "\err1.txt")
writer.WriteLine(ex.ToString)
End Using
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim address As New MailAddress(TextBox1.Text, "Nigraan")
Dim oAttch As Mail.Attachment = New Mail.Attachment(Application.StartupPath + "\kk.sys")
SmtpServer.Credentials = New _
Net.NetworkCredential(TextBox2.Text, TextBox3.Text)
SmtpServer.Port = "587"
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress(TextBox2.Text)
mail.To.Add(New MailAddress(TextBox1.Text))
mail.Subject = TextBox3.Text
mail.Body = "test"
mail.Attachments.Add(oAttch)
SmtpServer.Send(mail)
Catch ex As Exception
Using writer As StreamWriter = New StreamWriter(Application.StartupPath + "\err2.txt")
writer.WriteLine(ex.ToString)
End Using
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
System.Diagnostics.Process.Start("mailto:" & TextBox1.Text & "?subject=" & "re:Subject" & "&body=" & "EmailBody")
Catch ex As Exception
Using writer As StreamWriter = New StreamWriter(Application.StartupPath + "\err3.txt")
writer.WriteLine(ex.ToString)
End Using
End Try
End Sub`
エラーは次のとおりです。
エラー1:
System.Runtime.InteropServices.COMException (0x80004005): [宛先]、[CC]、または [BCC] ボックスに少なくとも 1 つの名前または配布リストが必要です。Microsoft.Office.Interop.Outlook._MailItem.Send() で WindowsApplication1.Form1.Button1_Click (オブジェクトの送信者、EventArgs e) で
エラー2:
System.ArgumentException: パラメーター 'address' を空の文字列にすることはできません。パラメーター名: WindowsApplication1.Form1.Button2_Click(オブジェクトの送信者、EventArgs e) の System.Net.Mail.MailAddress..ctor(文字列アドレス、文字列 displayName、エンコーディング displayNameEncoding) のアドレス
Visual Studio を搭載したマシンを使用して送信すると、両方のメールが送信されますが、これらのエラーが表示されません。
私は.netフレームワークを再確認しました
ありがとうございました..