Sending mails in vb.net 1.0

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Sending mails in vb.net 1.0

 
0
  #1
Nov 24th, 2008
Hi
i want to send a mail from vb.net 1.0. I have done some code for that as follows.
  1. Try
  2. myMessage = New System.Web.Mail.MailMessage
  3. With myMessage
  4. .To = sendTo
  5. .From = From
  6. .Subject = Subject
  7. .Body = Body
  8. .BodyFormat = System.Web.Mail.MailFormat.Text
  9. SMTPServer = "smtp.rediffmailpro.com"
  10.  
  11.  
  12.  
  13. If CC <> "" Then .Cc = CC
  14. If BCC <> "" Then .Bcc = ""
  15.  
  16. End With
  17.  
  18. System.Web.Mail.SmtpMail.Send(myMessage)

I have a rediffmailpro domain. When in "From mail id" I used my domain id its sending mail to any mail id i.e to gmail, yahoo etc. but when trying from other mail id's like gmail or yahoo its not giving error but mails also not sent.

please help me.. TIA.
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Sending mails in vb.net 1.0

 
0
  #2
Nov 24th, 2008
Most likely Rediffmailpro allows only mails from its own domain. This is to prevent sender forgery and spamming.

If you want to send mail from Gmail (or Yahoo) you have to have an account there and set SMTP server to smtp.googlemail.com (or smtp.gmail.com). Smtp.googlemail.com also uses port 587, requires SSL connections and you have to provide your credentials i.e. user name and password to Gmail account. AFAIK this is a bit difficult in .NET 1.0 (maybe even impossible), but can be done easily with .NET 2.0 and System.Net namespace. If you want for some reason to stick with .NET 1.0, take a look at Microsoft CDO Library (that's a COM object).
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,174
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 532
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Sending mails in vb.net 1.0

 
0
  #3
Nov 24th, 2008
do you mean 1 or 1.1 ?

1 is Visual Studio 2002 (Visual Studio .NET)
1.1 is Visual Studio 2003 (Visual Studio . NET 2003
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: Sending mails in vb.net 1.0

 
0
  #4
Nov 25th, 2008
Originally Posted by jbennet View Post
do you mean 1 or 1.1 ?

1 is Visual Studio 2002 (Visual Studio .NET)
1.1 is Visual Studio 2003 (Visual Studio . NET 2003
Hi
thanks for pointing my mistake. I am using,
1.1 is Visual Studio 2003 (Visual Studio . NET 2003
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: Sending mails in vb.net 1.0

 
0
  #5
Nov 25th, 2008
Originally Posted by Teme64 View Post
Most likely Rediffmailpro allows only mails from its own domain. This is to prevent sender forgery and spamming.

If you want to send mail from Gmail (or Yahoo) you have to have an account there and set SMTP server to smtp.googlemail.com (or smtp.gmail.com). Smtp.googlemail.com also uses port 587, requires SSL connections and you have to provide your credentials i.e. user name and password to Gmail account. AFAIK this is a bit difficult in .NET 1.0 (maybe even impossible), but can be done easily with .NET 2.0 and System.Net namespace. If you want for some reason to stick with .NET 1.0, take a look at Microsoft CDO Library (that's a COM object).
HI thanks for your reply.
Now I tried as follows,
  1. Dim CDOSYS As Object
  2. Const cdoSendUsingPickup = 1
  3. Const strPickup = "c:\inetpub\mailroot\pickup"
  4. CDOSYS = CreateObject("CDO.Message")
  5.  
  6. CDOSYS.Configuration.Fields.item _
  7. ("http://schemas.microsoft.com/cdo/configuration/sendusing") _
  8. = cdoSendUsingPickup
  9.  
  10. CDOSYS.Configuration.Fields.item _
  11. ("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") _
  12. = strPickup
  13.  
  14. CDOSYS.Configuration.Fields.Update()
  15. CDOSYS.To = txtTo.Text
  16. CDOSYS.From = txtFrom.Text
  17. CDOSYS.Subject = "CDO Test"
  18. CDOSYS.TextBody = "Send Email from vb.net using CDOSYS"
  19. CDOSYS.Send()
  20. CDOSYS = Nothing
  21. MsgBox("mail send")

This code sending my mails successfully, No exception raised. But all my mails are in "C:\Inetpub\mailroot\Badmail"
creating 3 files as ".BAD" , ".BDP" and ".BDR"


Can any one help me to send mail? I am Frustrated now ....
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Sending mails in vb.net 1.0

 
0
  #6
Nov 25th, 2008
Since you have 1.1, you can use System.Net namespace, Here's a sample for the Gmail but you can use the same code with other accounts too. Just change properties
  1. Imports System.Net
  2. Imports System.Net.Mail
  3.  
  4. Dim oSMTPCred As NetworkCredential
  5. Dim oSmtpClient As SmtpClient
  6. Dim AFrom As MailAddress
  7. Dim ATo As MailAddress
  8. Dim Addr As MailAddress
  9. Dim NewMsg As MailMessage
  10. Dim i As Integer
  11.  
  12. ' Set client for Gmail
  13. oSmtpClient = New SmtpClient
  14. oSmtpClient.Host = "smtp.gmail.com"
  15. oSmtpClient.Port = 587 ' Default port is 25
  16. oSmtpClient.Timeout = 15000 ' Milliseconds
  17. oSmtpClient.DeliveryMethod = Mail.SmtpDeliveryMethod.Network
  18.  
  19. ' Set credentials for Gmail and use SSL
  20. oSMTPCred = New NetworkCredential("your gmail address here", "and your password")
  21. oSmtpClient.UseDefaultCredentials = False
  22. oSmtpClient.Credentials = oSMTPCred
  23. oSmtpClient.EnableSsl = True
  24.  
  25. ' Compose message
  26. ATo = New MailAddress("john.doe@acme.com")
  27. AFrom = New MailAddress("your gmail address here")
  28. NewMsg = New MailMessage(AFrom, ATo)
  29.  
  30. NewMsg.Subject = "Test"
  31. NewMsg.Body = "Test"
  32. NewMsg.BodyEncoding = System.Text.Encoding.ASCII
  33.  
  34. ' Dummy vars for demo purpose
  35. Dim CC(0) As String
  36. Dim BCC(0) As String
  37. CC(0) = "john.doe@acme.com"
  38. BCC(0) = "john.doe@acme.com"
  39.  
  40. ' Set CC addresses
  41. For i = 0 To CC.GetUpperBound(0)
  42. Addr = New MailAddress(CC(i))
  43. NewMsg.CC.Add(Addr)
  44. Next i
  45. ' Set BCC addresses
  46. For i = 0 To BCC.GetUpperBound(0)
  47. Addr = New MailAddress(BCC(i))
  48. NewMsg.Bcc.Add(Addr)
  49. Next i
  50.  
  51. ' Finally, send the message
  52. oSmtpClient.Send(NewMsg)
AFAIK, Yahoo does not provide free SMTP. It's available only to business ($$$) customers.

I'm not familiar with Rediffmailpro but if you try with that, drop lines 19-23, or replace them with oSmtpClient.UseDefaultCredentials = True and change the Host and Port property values.

And forget that CDO thing, I shouldn't have mentioned it
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: Sending mails in vb.net 1.0

 
0
  #7
Nov 26th, 2008
Hi, Team64

thanks for your help. But when i am trying with the code you provided here , i got error for the following declaration.

Imports System.Net.Mail

Dim oSMTPCred As NetworkCredential
Dim oSmtpClient As SmtpClient
Dim AFrom As MailAddress
Dim ATo As MailAddress
Dim Addr As MailAddress
Dim NewMsg As MailMessage

Why so? any namespace is req. ? Plz help.
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Sending mails in vb.net 1.0

 
0
  #8
Nov 26th, 2008
Sorry, my mistake . System.Net.Mail is a .NET 2.0 assembly. However .NET 1.1 does have System.Web.Mail namespace. I checked its documentation and didn't find any way to set port, SSL, and credential information for SMTPServer. There may be a way to do it but I'm not aware of it. Somebody?

Your original code thus works with Rediffmailpro and other services which doesn't require credentials and use standard port 25. If you still want to use Gmail as the SMTP server, update to .NET 2.0. As you may know there are free Express Editions (2005/2008) for learning purposes.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,174
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 532
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Sending mails in vb.net 1.0

 
0
  #9
Nov 26th, 2008
Ive got a book on vb.net 2003 ill check...
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: Sending mails in vb.net 1.0

 
0
  #10
Nov 27th, 2008
Thanks guys...
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC