Hi
i want to send a mail from vb.net 1.0. I have done some code for that as follows.

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.

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).

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

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

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,

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 .... :'(

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

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)

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 ;)

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.

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.

This article has been dead for over six months. Start a new discussion instead.