| | |
Sending mails in vb.net 1.0
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
Hi
i want to send a mail from vb.net 1.0. I have done some code for that as follows.
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.
i want to send a mail from vb.net 1.0. I have done some code for that as follows.
VB.NET Syntax (Toggle Plain Text)
Try myMessage = New System.Web.Mail.MailMessage With myMessage .To = sendTo .From = From .Subject = Subject .Body = Body .BodyFormat = System.Web.Mail.MailFormat.Text SMTPServer = "smtp.rediffmailpro.com" If CC <> "" Then .Cc = CC If BCC <> "" Then .Bcc = "" End With 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... :)
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).
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).
Teme64 @ Windows Developer Blog
•
•
•
•
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).
Now I tried as follows,
VB.NET Syntax (Toggle Plain Text)
Dim CDOSYS As Object Const cdoSendUsingPickup = 1 Const strPickup = "c:\inetpub\mailroot\pickup" CDOSYS = CreateObject("CDO.Message") CDOSYS.Configuration.Fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") _ = cdoSendUsingPickup CDOSYS.Configuration.Fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") _ = strPickup CDOSYS.Configuration.Fields.Update() CDOSYS.To = txtTo.Text CDOSYS.From = txtFrom.Text CDOSYS.Subject = "CDO Test" CDOSYS.TextBody = "Send Email from vb.net using CDOSYS" CDOSYS.Send() CDOSYS = Nothing 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... :)
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
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
And forget that CDO thing, I shouldn't have mentioned it
VB.NET Syntax (Toggle Plain Text)
Imports System.Net 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 Dim i As Integer ' Set client for Gmail oSmtpClient = New SmtpClient oSmtpClient.Host = "smtp.gmail.com" oSmtpClient.Port = 587 ' Default port is 25 oSmtpClient.Timeout = 15000 ' Milliseconds oSmtpClient.DeliveryMethod = Mail.SmtpDeliveryMethod.Network ' Set credentials for Gmail and use SSL oSMTPCred = New NetworkCredential("your gmail address here", "and your password") oSmtpClient.UseDefaultCredentials = False oSmtpClient.Credentials = oSMTPCred oSmtpClient.EnableSsl = True ' Compose message ATo = New MailAddress("john.doe@acme.com") AFrom = New MailAddress("your gmail address here") NewMsg = New MailMessage(AFrom, ATo) NewMsg.Subject = "Test" NewMsg.Body = "Test" NewMsg.BodyEncoding = System.Text.Encoding.ASCII ' Dummy vars for demo purpose Dim CC(0) As String Dim BCC(0) As String CC(0) = "john.doe@acme.com" BCC(0) = "john.doe@acme.com" ' Set CC addresses For i = 0 To CC.GetUpperBound(0) Addr = New MailAddress(CC(i)) NewMsg.CC.Add(Addr) Next i ' Set BCC addresses For i = 0 To BCC.GetUpperBound(0) Addr = New MailAddress(BCC(i)) NewMsg.Bcc.Add(Addr) Next i ' Finally, send the message oSmtpClient.Send(NewMsg)
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
Teme64 @ Windows Developer Blog
Hi, Team64
thanks for your help. But when i am trying with the code you provided here , i got error for the following declaration.
Why so? any namespace is req. ? Plz help.
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 MailMessageWhy so? any namespace is req. ? Plz help.
Accept Challenges and Enjoy Coding... :)
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.
. 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.
Teme64 @ Windows Developer Blog
![]() |
Similar Threads
- Sendmail Configuration on new server (PHP)
- Sending mails...... (ASP.NET)
- Sending email using vb.net (VB.NET)
- How to send Attachments using perl script (Perl)
- can any help me in coading to access out look from vb.net (VB.NET)
- 'Symantec Email Proxy' (Viruses, Spyware and other Nasties)
- Email Sending Problem in ASP.NET (ASP.NET)
- Create double blind system in php (PHP)
- SMTP Times out in CommuniGate Pro (*nix Software)
Other Threads in the VB.NET Forum
- Previous Thread: loop through properties?
- Next Thread: I need Urgent help/guidance.
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic binary bing button buttons center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist excel file-dialog firewall folder ftp google hardcopy image images insert isnumericfuntioncall listview login math memory mobile ms navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port print problemwithinstallation project reports" save savedialog searchbox serial soap sorting string table tcp temp text textbox timer toolbox trim update updown upload useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf






