G
Guest
Hi There,
I use follow code to send email inside VB.NET 2005. It does not work well.
Error message of "Failure sending email" would occue. However, email was
sent out sometimes. I am confused and please help.
Thanks in advance.
Hugh
Imports System.net.Mail
Public Class Form1
Sub SendEmail(ByVal strFrom As String, ByVal strTo _
As String, ByVal strSubject As String, ByVal strMessage _
As String, ByVal file As String)
Try
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New
MailAddress(strTo))
MailMsg.Subject = strSubject.Trim()
MailMsg.Body = strMessage.Trim() & vbCrLf
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
MailMsg.Attachments.Add(MsgAttach)
End If
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.Host = "10.10.10.10"
SmtpMail.Send(MailMsg)
Catch ex As Exception
MessageBox.Show(ex.Message & " in SendEmail")
End Try
End Sub
Sub SendOneEmail()
Dim SendFrom, SendTo, Attach, strSubject, strMessage As String
Try
SendFrom = "(e-mail address removed)"
SendTo = “[email protected]â€
Attach = "c:\text.txt"
strSubject = “Email Subjectâ€
strMessage = “Email Body. This is a testâ€
SendEmail(SendFrom, SendTo, strSubject, strMessage, Attach)
Catch ex As Exception
MessageBox.Show(ex.Message & "in SendOneEmail")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SendOneEmail()
End Sub
End Class
I use follow code to send email inside VB.NET 2005. It does not work well.
Error message of "Failure sending email" would occue. However, email was
sent out sometimes. I am confused and please help.
Thanks in advance.
Hugh
Imports System.net.Mail
Public Class Form1
Sub SendEmail(ByVal strFrom As String, ByVal strTo _
As String, ByVal strSubject As String, ByVal strMessage _
As String, ByVal file As String)
Try
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New
MailAddress(strTo))
MailMsg.Subject = strSubject.Trim()
MailMsg.Body = strMessage.Trim() & vbCrLf
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
MailMsg.Attachments.Add(MsgAttach)
End If
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.Host = "10.10.10.10"
SmtpMail.Send(MailMsg)
Catch ex As Exception
MessageBox.Show(ex.Message & " in SendEmail")
End Try
End Sub
Sub SendOneEmail()
Dim SendFrom, SendTo, Attach, strSubject, strMessage As String
Try
SendFrom = "(e-mail address removed)"
SendTo = “[email protected]â€
Attach = "c:\text.txt"
strSubject = “Email Subjectâ€
strMessage = “Email Body. This is a testâ€
SendEmail(SendFrom, SendTo, strSubject, strMessage, Attach)
Catch ex As Exception
MessageBox.Show(ex.Message & "in SendOneEmail")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SendOneEmail()
End Sub
End Class