mike55 Posted March 29, 2004 Posted March 29, 2004 Hi Guys, Have been surfing the net looking for code that would allow me to send e-mails. Found the following code in the live demo at: http://www.4guysfromrolla.com/webtech/112298-1.shtml Now, am i right in saying that i simple just have to create an accout from which i can send the emails. But where in the code do i specify the password to the address (Know its a stupid question). <% If Len(Request.Form("txtEmail")) > 0 then Dim objMail Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = "info@4guysfromrolla.com (4GuysFromRolla.com)" objMail.Subject = "Email attachment demo" objMail.AttachFile Server.MapPath("/images/new468x60.gif") objMail.To = Request.Form("txtEmail") objMail.Body = "This is a demo on sending an email with an attachment." objMail.Send Response.write("<i>Mail was Sent</i><p>") 'You should always do this with CDONTS. set objMail = nothing End If %> <form method="post" id=form1 name=form1> <b>Enter your email address:</b><br> <input type="text" name="txtEmail" value="<%=Request.Form("txtEmail")%>"> <p> <input type="submit" value="Send me an Email with an Attachment!" id=submit1 name=submit1> </form> Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Superfly1611 Posted March 29, 2004 Posted March 29, 2004 Hi Guys, <% If Len(Request.Form("txtEmail")) > 0 then Dim objMail Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = "info@4guysfromrolla.com (4GuysFromRolla.com)" objMail.Subject = "Email attachment demo" objMail.AttachFile Server.MapPath("/images/new468x60.gif") objMail.To = Request.Form("txtEmail") objMail.Body = "This is a demo on sending an email with an attachment." objMail.Send Response.write("<i>Mail was Sent</i><p>") 'You should always do this with CDONTS. set objMail = nothing End If %> <form method="post" id=form1 name=form1> <b>Enter your email address:</b><br> <input type="text" name="txtEmail" value="<%=Request.Form("txtEmail")%>"> <p> <input type="submit" value="Send me an Email with an Attachment!" id=submit1 name=submit1> </form> This is actually classic ASP, did you want a .Net sollution (This is a .Net board)? However it makes little difference to your question, The answer is... you don't As long as you have CDonts registered on your machine and have installed an SMTP server then all you have to do is write in plain text the address (yes it can be fictitious) that you are sending it from Quote
Arch4ngel Posted March 29, 2004 Posted March 29, 2004 Tell me if you want really to logon to a SMTP server. You'll however need the cdosys.dll from Windows Server and I got the right code to connect yourself. Tell me if you are interested. (If your machine have an SMTP server on it it'll not be necessary) Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mike55 Posted March 29, 2004 Author Posted March 29, 2004 Tell me if you want really to logon to a SMTP server. You'll however need the cdosys.dll from Windows Server and I got the right code to connect yourself. Tell me if you are interested. (If your machine have an SMTP server on it it'll not be necessary) Yea, would appreciate it, always looking for options. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Arch4ngel Posted March 29, 2004 Posted March 29, 2004 Sending email Yea' date=' would appreciate it, always looking for options.[/quote'] [size=2][color=#0000ff]public[/color][/size][size=2][color=#0000ff]void[/color][/size][size=2] SendEmployeeList( DataTable dt, [/size][size=2][color=#0000ff]string[/color][/size][size=2] HTML) { [/size][size=2][color=#0000ff]string[/color][/size][size=2] to = [email="mike55@hotmail.com"]mike55@hotmail.com[/email]; [/size][size=2][color=#0000ff]string[/color][/size][size=2] from = [email="someone@microsoft.com"]someone@microsoft.com[/email]; [/size][size=2][color=#0000ff]string[/color][/size][size=2] subj = "This is the subject line"; [/size][size=2][color=#0000ff]string[/color][/size][size=2] username = "USERNAME"; [/size][size=2][color=#0000ff]string[/color][/size][size=2] password = "PASSWORD";[/size] [size=2][size=2]Message msg = [/size][size=2][color=#0000ff]new[/color][/size][size=2] MessageClass(); [/size][size=2]msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = m_Serveur; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = m_Port; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CdoSendUsing.cdoSendUsingPort; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = username; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = password; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = CdoProtocolsAuthentication.cdoBasic; [/size][size=2]msg.Configuration.Fields.Update(); [size=2]msg.To = to; msg.From = from; msg.Subject = subj; [/size][size=2]msg.HTMLBody = HTML; [/size][size=2]msg.Send(); [/size][/size][/size][size=2]} [/size] Note: You must add a reference to the "cdosys.dll". You can find it on the web. I don't think I could send you the DLL through this forum. After you add the reference... a simple using CDO; using ADODB; And the job's done. N.B.: You could add a try catch if the send fails. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mike55 Posted March 30, 2004 Author Posted March 30, 2004 [size=2][color=#0000ff]public[/color][/size][size=2][color=#0000ff]void[/color][/size][size=2] SendEmployeeList( DataTable dt, [/size][size=2][color=#0000ff]string[/color][/size][size=2] HTML) { [/size][size=2][color=#0000ff]string[/color][/size][size=2] to = [email="mike55@hotmail.com"]mike55@hotmail.com[/email]; [/size][size=2][color=#0000ff]string[/color][/size][size=2] from = [email="someone@microsoft.com"]someone@microsoft.com[/email]; [/size][size=2][color=#0000ff]string[/color][/size][size=2] subj = "This is the subject line"; [/size][size=2][color=#0000ff]string[/color][/size][size=2] username = "USERNAME"; [/size][size=2][color=#0000ff]string[/color][/size][size=2] password = "PASSWORD";[/size] [size=2][size=2]Message msg = [/size][size=2][color=#0000ff]new[/color][/size][size=2] MessageClass(); [/size][size=2]msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = m_Serveur; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = m_Port; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CdoSendUsing.cdoSendUsingPort; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = username; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = password; msg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = CdoProtocolsAuthentication.cdoBasic; [/size][size=2]msg.Configuration.Fields.Update(); [size=2]msg.To = to; msg.From = from; msg.Subject = subj; [/size][size=2]msg.HTMLBody = HTML; [/size][size=2]msg.Send(); [/size][/size][/size][size=2]} [/size] Note: You must add a reference to the "cdosys.dll". You can find it on the web. I don't think I could send you the DLL through this forum. After you add the reference... a simple using CDO; using ADODB; And the job's done. N.B.: You could add a try catch if the send fails. Ok i have taken the code and have attempted to translate it into VB.NET. I have also downloaded and added a reference to the .dll file (have also followed the instructions on how to register it), however i have been unable to convert the msg.Configuration.Fields entry to VB.NET, any suggestions. Here is the translation so far. Imports CDONTS Imports ADODB Imports System.Web.Mail Try Dim ReceiverAddress As String = "mikeodonnell55@netscape.net" Dim SendersAddress As String = "admiralodonnell_cinc@hotmail.com" Dim subject As String = "This is a test" Dim username As String = "admiralodonnell_cinc" Dim password As String = "hmsinvincible" Dim msg As New NewMailClass msg.To = ReceiverAddress msg.From = SendersAddress msg.Subject = subject msg.Body = "Sorry if you receive this by accident, this is a test." msg.Send() Catch ex As Exception Throw ex End Try Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
MorningZ Posted March 30, 2004 Posted March 30, 2004 Works for me... Dim mail As New MailMessage mail.To = "someone@there.com" mail.From = "someone@here.com"" mail.Subject = "Test!" mail.Body = "Tesing!" mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "EmailAccountUserName") 'set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "EmailAccountPass") 'set your password here SmtpMail.SmtpServer = "mail.here.com" Try SmtpMail.Send(mail) Catch ex As Exception 'Error!!! End Try Quote If you make it idiot proof, they'll build a better idiot :-)
MorningZ Posted March 30, 2004 Posted March 30, 2004 btw.. got that off the sticky pasted at the top of this very forum aptly named "Sticky: System.Web.Mail" Quote If you make it idiot proof, they'll build a better idiot :-)
Arch4ngel Posted March 31, 2004 Posted March 31, 2004 It work only if you have a SMTP server that don't require Authentication. But most of them now require one! At least everybody got a SMTP server on there machine it won't work. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
MorningZ Posted March 31, 2004 Posted March 31, 2004 It work only if you have a SMTP server that don't require Authentication. But most of them now require one! At least everybody got a SMTP server on there machine it won't work. the code does work on mail servers that require authentication..... Quote If you make it idiot proof, they'll build a better idiot :-)
Arch4ngel Posted March 31, 2004 Posted March 31, 2004 Hummmmm... Have you some sample code ? Can't think I've go beside that without testing this. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Arch4ngel Posted March 31, 2004 Posted March 31, 2004 Forget it. It work the way you said (but in C#). For the authentication it just need some "Fields". Hehe I've been such a moron during a day looking for this. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
MorningZ Posted March 31, 2004 Posted March 31, 2004 bah, you got it working.. thats all that counts :-) thank god programming ain't easy, cause a lotta us would be out of some jobs, lol Quote If you make it idiot proof, they'll build a better idiot :-)
mike55 Posted March 31, 2004 Author Posted March 31, 2004 In relation to the VB.NET code supplied by MorningZ, well i put it all behind a button, filled in the to and from address spaces with proper email accounts, have set the Smtp server to hotmail ("http://services.msn.com/svcs/hotmail/httpmail.asp") filled in the correct username(username@hotmail.com) and password and built the solution. However am now getting a transport problem(transport failed to connect to the server problem)!! Ahhh my head will explode!!! Dim mail As New MailMessage mail.To = "Receivers_Account@eircom.net" mail.From = "MyAccount@hotmail.com" mail.Subject = "Test!" mail.Body = "Tesing!" mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "MyAccount@hotmail.com") 'set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*****") 'set your password here SmtpMail.SmtpServer = "http://services.msn.com/svcs/hotmail/httpmail.asp" Try SmtpMail.Send(mail) lblOutput.Text = "Looking good" Catch ex As Exception Throw ex End Try Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted March 31, 2004 Administrators Posted March 31, 2004 the .SmtpServer should be the address of a valid smtp server - you appear to be setting it to a web-site. Hotmail is a web based mail service and I don't think you can access as if it was a smtp based mail server. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mike55 Posted March 31, 2004 Author Posted March 31, 2004 the .SmtpServer should be the address of a valid smtp server - you appear to be setting it to a web-site. Hotmail is a web based mail service and I don't think you can access as if it was a smtp based mail server. Can you suggest any alternative provider?? Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
MorningZ Posted April 1, 2004 Posted April 1, 2004 wow, i've never seen anyone try to send out through Hotmail from a web app (is that even possible??) Other options: - Use the SMTP server of the server itself (its right there in control panel / windows components) - Pay like $8 for a good web host account that includes mail (like this one: http://www.crystaltech.com/shared.htm) Quote If you make it idiot proof, they'll build a better idiot :-)
Arch4ngel Posted April 1, 2004 Posted April 1, 2004 Or simply install a Smtp Server on your machine and send email from there... need a permanant connection and maybe a server if you want something good. Otherwise : $8 for a web host account with mail :D Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
mike55 Posted April 2, 2004 Author Posted April 2, 2004 Hi guys Finally got the email system working. Had to use an account from oceanfree.net to get it working. By using the code supplied by MorningZ, and adapting the SMTPServer to SmtpMail.SmtpServer = "smtp.oceanfree.net" was able to send the email, Norton even scanned the email as it went out. Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.