send email
-
i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks <pre> ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) *** function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL) on error resume next dim Mailer set Mailer = server.createobject("CDO.Message") if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if Mailer.From = FromName & " <" & FromEmail & ">" Mailer.To = ToName & " <" & ToEmail & ">" Mailer.TextBody = Message Mailer.Subject = Subject with Mailer.Configuration .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com" .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword" .Fields.Update end with Mailer.Send if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if set Mailer = Nothing CDOSYS_Mailer = true end function</pre>
-
i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks <pre> ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) *** function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL) on error resume next dim Mailer set Mailer = server.createobject("CDO.Message") if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if Mailer.From = FromName & " <" & FromEmail & ">" Mailer.To = ToName & " <" & ToEmail & ">" Mailer.TextBody = Message Mailer.Subject = Subject with Mailer.Configuration .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com" .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword" .Fields.Update end with Mailer.Send if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if set Mailer = Nothing CDOSYS_Mailer = true end function</pre>
.NET has its own built in ways of sending mail. You want to read MSDN and look up the System.Net.Mail namespace and specifically the SmtpClient[^] class.
Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual
-
i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks <pre> ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) *** function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL) on error resume next dim Mailer set Mailer = server.createobject("CDO.Message") if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if Mailer.From = FromName & " <" & FromEmail & ">" Mailer.To = ToName & " <" & ToEmail & ">" Mailer.TextBody = Message Mailer.Subject = Subject with Mailer.Configuration .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com" .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword" .Fields.Update end with Mailer.Send if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if set Mailer = Nothing CDOSYS_Mailer = true end function</pre>
Dim message As New MailMessage("sender@address", "from@address", "Subject", "Message Text") Dim emailClient As New SmtpClient("Email Server Name") emailClient.Send(message)
That will do the job. However, this code is one of the snippets in Visual basic, so how you didnt find it I dont know :doh: . And its not that hard to search google for this, and for possibly more reliable results try MSDN.Lloyd J. Atkinson
-
i am new to vb.net. i would like to create a class for sending emial . i tried the script online but i failed to send. So i got this code below from the hosting server. May i know how do i simplify the below script to just receive FromEmail, Subject, Message ? why it needs the mailerpath?mailerport? and errText? isn't we can check those error in the form instead of class ? Please kindly advice. thanks <pre> ' **** MailerPath = Your SMTP path (for eg: mail.[domain].com) *** function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName, Subject, MailerPath, MailerPort, errText, searchURL) on error resume next dim Mailer set Mailer = server.createobject("CDO.Message") if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if Mailer.From = FromName & " <" & FromEmail & ">" Mailer.To = ToName & " <" & ToEmail & ">" Mailer.TextBody = Message Mailer.Subject = Subject with Mailer.Configuration .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailerPath .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailerPort .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="test@yourdomain.com" .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="youremailpassword" .Fields.Update end with Mailer.Send if err.number <> 0 then errText = displayError("CDOSYS", searchURL, err.Number, err.Source, err.Description) CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0 exit function end if set Mailer = Nothing CDOSYS_Mailer = true end function</pre>
You won't learn VB.NET by trying to copy code snippets off the web that you don't understand. This is a TERRIBLE way to send mail, as others said, the mail classes are built in. I would recommend reading my article on how to use google, it actually uses sending an email as an example. I would also recommend buying a book and working through it, learning how to program VB.NET incrementally instead of trying to learn how to copy and paste other people's code that is above your head.
Christian Graus Driven to the arms of OSX by Vista.
-
You won't learn VB.NET by trying to copy code snippets off the web that you don't understand. This is a TERRIBLE way to send mail, as others said, the mail classes are built in. I would recommend reading my article on how to use google, it actually uses sending an email as an example. I would also recommend buying a book and working through it, learning how to program VB.NET incrementally instead of trying to learn how to copy and paste other people's code that is above your head.
Christian Graus Driven to the arms of OSX by Vista.