' Create this class the accepts parameters and note that you need to include this namespace
Public
Class email
Public Sub SendEmail(ByVal strTo
As String,
ByVal strFrom
As String,
ByVal strSubject
As String,
ByVal strBody
As String)
Dim email As
New System.Web.Mail.MailMessage
email.To = strTo
email.From = strFrom
email.Body = strBody
email.Subject = strSubject
email.BodyFormat = Web.Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
System.Web.Mail.SmtpMail.Send(email)
End Sub
End
Class
Private Sub butMail_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles butMail.Click
'Go to virus console of macafee, access protection,
' uncheck prevent mass mailing worms from sending mail, port 25
Dim myEmail
As New email
myEmail.SendEmail("enter to email", "enter from email", "subject", "body!!")
I have a question.
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
How about if i want to test the sending email in localhost. Can i show the sender and receiver email?
How should i do in order to show the sender and receiver email in localhost.
' Create this class the accepts parameters and note that you need to include this namespace
Public
Class email
Public Sub SendEmail(ByVal strTo
As String,
ByVal strFrom
As String,
ByVal strSubject
As String,
ByVal strBody
As String)
Dim email As
New System.Web.Mail.MailMessage
email.To = strTo
email.From = strFrom
email.Body = strBody
email.Subject = strSubject
email.BodyFormat = Web.Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
System.Web.Mail.SmtpMail.Send(email)
End Sub
End
Class
this code have a problem
if u give any smtp then server replies error
b.z it need a password of given From id
ATHENTICATION ERROR
plz solve the problem
next problem some server chage is ports thier smtp ports is not 25 how to solve this problem
i am waiting your reply plz as ealry as possible reply
If you need to authenticate before sending an email (for the From Address), here is a quick code snippet I grabbed from the site mentioned above that may help:
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here
SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here
SmtpMail.Send(mail)
Could be your SMTPServer setting in the code. Check out the site that I listed in my original post and you will find more details. I've run into situations where it required me to set the SMTPServer setting to "" (as it was configured locally).
quyetnguyen, you are in big trouble with that message.... either:
1.- You don´t have CDO registered in your system...
2.- CDO dll is corrupted
I had to deal with that error some time ago... couldn´t solve it.
I found a component called "JMail" (search for it in google) much easier to use, I would take a look at
it to see if it solves ur problem, btw it´s free...
Is there a way to have the e-mail sent upon processing of the page? More specifically, I'd like to have my homepage automatically send me an email when someone accesses the site, and include some IP address and browser info in the message body, all without
user interaction.
quyetnguyen, I used to be haunted by the "Could not access 'CDO.Message' object."
I changed my email function to help me determine what the real problem was. You have to look in some of the inner exceptions to find the real problem.
Imports
System.Web.Mail
Public Class cEmail
Public ErrorMessage
As String
Public Function SendEmail(ByVal strTo
As String,
ByVal strFrom
As String,
ByVal strSubject
As String,
ByVal strBody
As String,
ByVal format As MailFormat)
As Boolean
ErrorMessage = String.Empty
Try
Dim myMailMessage
As New MailMessage
myMailMessage.To = strTo
myMailMessage.From = strFrom
myMailMessage.Subject = strSubject
myMailMessage.Body = strBody
myMailMessage.BodyFormat = format
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SMTPServer")
SmtpMail.Send(myMailMessage)
Return
True
Catch ex
As Exception
ErrorMessage = ex.Message
If Not ex.InnerException
Is Nothing
Then
ErrorMessage &= ex.InnerException.Message
If
Not ex.InnerException.InnerException
Is Nothing
Then
ErrorMessage &= ex.InnerException.InnerException.Message
End
If
End If
Return
False
End Try
End Function
End Class
If SendEmail returns false then the ErrorMessage will contain a more detailed error message that will help find the real problem. I have had problems with the SMTP server not relaying the message because I was coming from an untrusted
IP Address. I would not have known without seeing the InnerException message
This is the simplest and very powerfull solution I'va never found on the Web to solve the "CDO message" when sending an email via System.Web.Mail namespace.
Since many months, I was not able to know what was the core problem of that error in my ASP.NET and VB.NET applications. But today, with the errors management code suggested by joe0928 , I can now know easily was is the specific error being thrown by the
system.
For my case, I was an error in my code. The database field from my SQL Database was empty and I was saving that empty value in the "To" parameter of my message instaed of saving it into the "Cc" parameter.
Most of time, that error is caused by wrong addresses (To, CC or Bcc or invalid attachments).
coolguy
Member
25 Points
5 Posts
Sending email - the easy way (for vb.net geeks)
Jun 27, 2005 04:22 AM|LINK
' Create this class the accepts parameters and note that you need to include this namespace
Class email Public Sub SendEmail(ByVal strTo As String, ByVal strFrom As String, ByVal strSubject As String, ByVal strBody As String) Dim email As New System.Web.Mail.MailMessagePublic
email.To = strTo
email.From = strFrom
email.Body = strBody
email.Subject = strSubject
email.BodyFormat = Web.Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
System.Web.Mail.SmtpMail.Send(email)
End SubEnd
ClassPrivate Sub butMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butMail.Click 'Go to virus console of macafee, access protection, ' uncheck prevent mass mailing worms from sending mail, port 25 Dim myEmail As New email
myEmail.SendEmail("enter to email", "enter from email", "subject", "body!!")
End SubSimple
Member
5 Points
1 Post
Re: Sending email - the easy way (for vb.net geeks)
Jun 29, 2005 04:47 AM|LINK
I have a question.
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
How about if i want to test the sending email in localhost. Can i show the sender and receiver email?
How should i do in order to show the sender and receiver email in localhost.
Khubpk
Member
15 Points
3 Posts
Re: Sending email - the easy way (for vb.net geeks)
Jul 10, 2005 06:27 PM|LINK
' Create this class the accepts parameters and note that you need to include this namespace
Class email Public Sub SendEmail(ByVal strTo As String, ByVal strFrom As String, ByVal strSubject As String, ByVal strBody As String) Dim email As New System.Web.Mail.MailMessagePublic
email.To = strTo
email.From = strFrom
email.Body = strBody
email.Subject = strSubject
email.BodyFormat = Web.Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "enter your mail server name"
System.Web.Mail.SmtpMail.Send(email)
End SubEnd
Classthis code have a problem
if u give any smtp then server replies error
b.z it need a password of given From id
ATHENTICATION ERROR
plz solve the problem
next problem some server chage is ports thier smtp ports is not 25 how to solve this problem
i am waiting your reply plz as ealry as possible reply
ITSOLGood
Member
39 Points
16 Posts
Re: Sending email - the easy way (for vb.net geeks)
Jul 13, 2005 02:55 PM|LINK
http://www.systemwebmail.com/
If you need to authenticate before sending an email (for the From Address), here is a quick code snippet I grabbed from the site mentioned above that may help:
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here
SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here
SmtpMail.Send(mail)
Hope this helps.
quyetnguyen
Member
15 Points
3 Posts
Re: Sending email - the easy way (for vb.net geeks)
Jul 14, 2005 01:48 AM|LINK
have to i do ?
thanks!
ITSOLGood
Member
39 Points
16 Posts
Re: Sending email - the easy way (for vb.net geeks)
Jul 14, 2005 01:30 PM|LINK
JUtrilla
Member
105 Points
21 Posts
Re: Sending email - the easy way (for vb.net geeks)
Aug 31, 2005 02:21 PM|LINK
1.- You don´t have CDO registered in your system...
2.- CDO dll is corrupted
I had to deal with that error some time ago... couldn´t solve it.
I found a component called "JMail" (search for it in google) much easier to use, I would take a look at
it to see if it solves ur problem, btw it´s free...
Good luck!.
GreggGr
Member
5 Points
1 Post
Re: Sending email - the easy way (for vb.net geeks)
Oct 05, 2005 04:16 PM|LINK
Is there a way to have the e-mail sent upon processing of the page? More specifically, I'd like to have my homepage automatically send me an email when someone accesses the site, and include some IP address and browser info in the message body, all without user interaction.
joe0928
Member
125 Points
25 Posts
Re: Sending email - the easy way (for vb.net geeks)
Oct 17, 2005 09:14 PM|LINK
I changed my email function to help me determine what the real problem was. You have to look in some of the inner exceptions to find the real problem.
Imports
System.Web.MailPublic Class cEmail
Public ErrorMessage As String
Public Function SendEmail(ByVal strTo As String, ByVal strFrom As String, ByVal strSubject As String, ByVal strBody As String, ByVal format As MailFormat) As Boolean
ErrorMessage = String.Empty
Try
Dim myMailMessage As New MailMessage
myMailMessage.To = strTo
myMailMessage.From = strFrom
myMailMessage.Subject = strSubject
myMailMessage.Body = strBody
myMailMessage.BodyFormat = format
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SMTPServer")
SmtpMail.Send(myMailMessage)
Return True
Catch ex As Exception
ErrorMessage = ex.Message
If Not ex.InnerException Is Nothing Then
ErrorMessage &= ex.InnerException.Message
If Not ex.InnerException.InnerException Is Nothing Then
ErrorMessage &= ex.InnerException.InnerException.Message
End If
End If
Return False
End Try
End Function
End Class
If SendEmail returns false then the ErrorMessage will contain a more detailed error message that will help find the real problem. I have had problems with the SMTP server not relaying the message because I was coming from an untrusted IP Address. I would not have known without seeing the InnerException message
mackson
Member
5 Points
1 Post
Re: Sending email - the easy way (for vb.net geeks)
Jan 24, 2006 06:39 AM|LINK
This is the simplest and very powerfull solution I'va never found on the Web to solve the "CDO message" when sending an email via System.Web.Mail namespace.
Since many months, I was not able to know what was the core problem of that error in my ASP.NET and VB.NET applications. But today, with the errors management code suggested by joe0928 , I can now know easily was is the specific error being thrown by the system.
For my case, I was an error in my code. The database field from my SQL Database was empty and I was saving that empty value in the "To" parameter of my message instaed of saving it into the "Cc" parameter.
Most of time, that error is caused by wrong addresses (To, CC or Bcc or invalid attachments).
Thank you joe0928.