how do i send an email to a user via code

id like to send an email of usersemail and password from my program (UsersEmail,Password) how do i send an email of lets say;

------------ begin email --------------
This email is so you may keep a record of your email and password


E-Mail: UsersEmail
Password: Password

Please save this message for your records in case you lose your logon information

----------------- end email ----------------

how do i send this via my program with haveing UsersEmail and Password populated with the info.
UsersEmail is the email im going to send to as well

thx
Johnny
aka Pern
JohnnyAsked:
Who is Participating?
 
tusharashahConnect With a Mentor Commented:
I want to get this solved as much as you..

Your new SendEmail function will look like following:

----------------------------------------------------------------------------------------------------
Public Function SendEmail()
        ''    Property Description:
        ''Attachments   Used for sending e-mails with attachments
        ''From          Sender's e-mail address
        ''To            Recipient's e-mail address
        ''Cc            Recipient's e-mail address (Carbon Copy)
        ''Bcc           Recipient's e-mail address (Blind Carbon Copy)
        ''Body          Text of the e-mail message
        ''BodyFormat    Specifies the format of an e-mail message (Possible Values: Text, Html)
        ''Subject       Denotes the subject of an e-mail message
        ''BodyEncoding  Specifies the method of encoding an e-mail message (Possible Values: Base64 and UUEncode)

        Dim msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

        msg.From = "YourEmail@Email.com"
        msg.Subject = "Your Subject"
        msg.Body = "Your Body"
        msg.To = "Email@yahoo.com"
        msg.Bcc = "IfAny@anything.com"
        System.Web.Mail.SmtpMail.SmtpServer = "Localhsot"
        System.Web.Mail.SmtpMail.Send(msg)

    End Function
----------------------------------------------------------------------------------------------------

Tell me your development environment..

-tushar
0
 
tusharashahCommented:
Hi Pern,
Which Language you'll be using?

Following is code in C# & VB.Net for this
---------------------------------------------------------------------------------------------------------------------
C#
-------
public void SendEmail()
{
      MailMessage msg = new MailMessage();
      msg.From = "YourEmail@Email.com";
      msg.Subject = "Your Subject";
      msg.Body = "Your Body";
      msg.To = "Email@yahoo.com";
      msg.Bcc = "IfAny@anything.com";
      SmtpMail.SmtpServer = "localhost";   // your SMTP server
      SmtpMail.Send(msg);
}

VB.Net
--------
Public Sub SendEmail()
 Dim msg As MailMessage = New MailMessage ()
 msg.From = "YourEmail@Email.com"
 msg.Subject = "Your Subject"
 msg.Body = "Your Body"
 msg.To = "Email@yahoo.com"
 msg.Bcc = "IfAny@anything.com"
 SmtpMail.SmtpServer = "localhost"
 SmtpMail.Send(msg)
End Sub
---------------------------------------------------------------------------------------------------------------------

-tushar
0
 
JohnnyAuthor Commented:
VB.Net
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
tusharashahCommented:
Well that was irrilavent question from me.. realize that I was in VB.Net section.. the code in Vb.Net is right there.. also check out following property of MailMessage class that you can use..

You'll need to use using System.Web.Mail namespace.


Property Description:
Attachments             Used for sending e-mails with attachments
From                       Sender's e-mail address
To                           Recipient's e-mail address
Cc                           Recipient's e-mail address (Carbon Copy)
Bcc                          Recipient's e-mail address (Blind Carbon Copy)
Body                        Text of the e-mail message
BodyFormat              Specifies the format of an e-mail message (Possible Values: Text, Html)
Priority                     Specifies the priority of an e-mail message (Possible Values: High, Low, and Normal)
Subject                    Denotes the subject of an e-mail message
Headers                   Denotes a collection of acceptable headers (Example: Reply-To)
BodyEncoding           Specifies the method of encoding an e-mail message (Possible Values: Base64 and UUEncode)

-tushar
0
 
JohnnyAuthor Commented:
great for sending the email the sub...thx

i get how just do

msg.Body = "Your Body" & UsersEmail & "more msg body"

for sending my info

thanks that wroks for me

Johnny
aka Pern
0
 
JohnnyAuthor Commented:
dang it it says
      Error      1            Type 'MailMessage' is not defined.

      Error      2            Name 'SmtpMail' is not declared.

i hate whenit does that... thats a include thing right ??

                  
                  
0
 
JohnnyAuthor Commented:
thx for the nifty property discrip too
0
 
tusharashahCommented:
I mentioned that in my lastpost:

You'll need

System.Web.Mail

-tushar
0
 
JohnnyAuthor Commented:
my fault sorry
0
 
tusharashahCommented:
Oh dont worry, that happens.. post back if you got it working :>
0
 
JohnnyAuthor Commented:
     Error      1            'Mail' is not a member of 'Web'.


i put this in my modual so i can (at some point pass the values to it and reuse it...(if i can figure that out)

im still learning this so please bare with me

heres my function
 Public Function SendEmail()
        Using System.Web.Mail


            ''    Property Description()
            ''Attachments             Used for sending e-mails with attachments
            ''       From(Sender) 's e-mail address
            ''To                           Recipient's e-mail address
            ''        Cc(Recipient) 's e-mail address (Carbon Copy)
            ''        Bcc(Recipient) 's e-mail address (Blind Carbon Copy)
            ''Body                        Text of the e-mail message
            ''BodyFormat              Specifies the format of an e-mail message (Possible Values: Text, Html)
            ''Subject                    Denotes the subject of an e-mail message
            ''BodyEncoding           Specifies the method of encoding an e-mail message (Possible Values: Base64 and UUEncode)

            Dim msg As MailMessage = New MailMessage()
            msg.From = "YourEmail@Email.com"
            msg.Subject = "Your Subject"
            msg.Body = "Your Body"
            msg.To = "Email@yahoo.com"
            msg.Bcc = "IfAny@anything.com"
            SmtpMail.SmtpServer = "localhost"
            SmtpMail.Send(msg)
        End Using
    End Function

sorry for aksing all these dum questions..
0
 
tusharashahCommented:
2 Correction:

1) Replace
-->> Using System.Web.Mail
with --> Imports System.Web.Mail

2) And you'll put this with other Import on the top
(eg. Imports System.Data  )


-tushar

0
 
JohnnyAuthor Commented:
     Error      1            Namespace or type specified in the Imports 'System.Web.Mail' cannot be found.      

LOL ok now its really broken (smile)

i put  it out side the Module Module1 very top line
                  
0
 
JohnnyAuthor Commented:
how about we make this easy lets say its the only think in a modual and i want to pass all this info to it how do i do that...
and whats the line to fire it all??

maybe i wont get any errors then

thx
0
 
tusharashahCommented:
hmmm.. damn..

Replace:
         Dim msg As MailMessage = New MailMessage()
With:
        Dim msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

-tushar
0
 
JohnnyAuthor Commented:
still have same other errors and new one
      Error      1            Namespace or type specified in the Imports 'System.Web.Mail' cannot be found.

ok heres my complete code in modual

----------- code -------

Imports System.Web.Mail
Module Module1
    Public Function AppPath(Optional ByVal WithSlash As Boolean = False) As String
        'Dim a As String = AppPath(True) & "somepic.jpg"
        'Dim b As String = AppPath(False) & "\somepic.jpg"
        'Dim c As String = Application.StartupPath
        'Dim d As String = Environment.CurrentDirectory
        'Dim e As String = Application.ExecutablePath

        'MsgBox(a & vbCrLf & b & vbCrLf & c & vbCrLf & d & vbCrLf & e)

        Dim Result As String = Application.StartupPath
        If WithSlash Then
            If Result.EndsWith("\") = False Then
                Result &= "\"
            End If
        Else
            If Result.EndsWith("\") Then
                Result = Strings.Left(Result, Len(Result) - 1)
            End If
        End If
        Return Result
    End Function

    Public Function deleteFile(ByVal fileName As String)
        If System.IO.File.Exists(fileName) Then
            Try
                System.IO.File.Delete(fileName)
            Catch ex As Exception
                MsgBox(fileName & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "Unable to delete file")
            End Try
        Else
            MsgBox(fileName, MsgBoxStyle.Critical, "File does not exist")
        End If

    End Function
    Public Function DownloadFile(ByVal uri As String, ByVal destFile As String, _
        Optional ByVal username As String = Nothing, Optional ByVal pwd As String = _
        Nothing)
        Dim wc As New System.Net.WebClient
        ''Dim myWebClient As New WebClient
        If Not username Is Nothing AndAlso Not pwd Is Nothing Then
            wc.Credentials = New System.Net.NetworkCredential(username, pwd)
        End If

        Try

            wc.DownloadFile(uri, destFile)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function

    Public Function SendEmail()

        ''    Property Description:
        ''Attachments   Used for sending e-mails with attachments
        ''From          Sender's e-mail address
        ''To            Recipient's e-mail address
        ''Cc            Recipient's e-mail address (Carbon Copy)
        ''Bcc           Recipient's e-mail address (Blind Carbon Copy)
        ''Body          Text of the e-mail message
        ''BodyFormat    Specifies the format of an e-mail message (Possible Values: Text, Html)
        ''Subject       Denotes the subject of an e-mail message
        ''BodyEncoding  Specifies the method of encoding an e-mail message (Possible Values: Base64 and UUEncode)

        Dim msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

        msg.From = "YourEmail@Email.com"
        msg.Subject = "Your Subject"
        msg.Body = "Your Body"
        msg.To = "Email@yahoo.com"
        msg.Bcc = "IfAny@anything.com"
        SmtpMail.SmtpServer = "localhost"
        SmtpMail.Send(msg)

    End Function

End Module
                  
0
 
tusharashahCommented:
When you replace with following line you dont need Imports..

Dim msg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage


& with Imports:
 make sure Imports is the top most line and outside your Class

-tushar
0
 
JohnnyAuthor Commented:
     Error      1            Type 'System.Web.Mail.MailMessage' is not defined.
      Error      2            Name 'SmtpMail' is not declared.
      Error      3            Name 'SmtpMail' is not declared.

took out
Imports System.Web.Mail

left
Module Module1

still no joy!
0
 
tusharashahCommented:
I'm feeling the joy..

You also need to replace:
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(msg)

with:
        System.Web.Mail.SmtpMail.SmtpServer = "localhost"
        System.Web.Mail.SmtpMail.Send()

-tushar
0
 
tusharashahCommented:
Also, since you're getting all short of errors.. if IN CASE you get any errors regarding RELAY then do following:

Go to:
 Administrator Tools --> IIS --> Default SMTP Server --> Properties --> Access --> Relay
& Make sure you have selected 'all except the list below'

-tushar
0
 
JohnnyAuthor Commented:
     Error      1            Type 'System.Web.Mail.MailMessage' is not defined.
      Error      2            'Mail' is not a member of 'Web'.
      Error      3            'Mail' is not a member of 'Web'.

replaced as said.. and JOY went and left the bulding (smile)

thx for helping btw and being understanding
0
 
JohnnyAuthor Commented:
i dont use IIs.. im useing argosoft's email server...with xp pro.. and apache/php/mysql as web space..

im also programming this in vb 2005 express in case that makes a diffrence

ill look that up and tell u on next volly what it is
i asume its bult into xp and uses it regardless if IIS is installed(or default install)
0
 
JohnnyAuthor Commented:
nope no IIS
0
 
JohnnyAuthor Commented:
it look as you said... and did that in l;ast message

and thx for your persistance im inpressed
0
 
tusharashahCommented:
Just in case I am missing something take a look at following link from microsoft:

http://support.microsoft.com/default.aspx?scid=kb;en-us;314201

-tushar
0
 
tusharashahCommented:
This could be the case: (taken from above mentioned link)

Add a reference to System.Web.dll. To do this, follow these steps:
a.  On the Project menu, click Add Reference.
b.  On the .NET tab, locate System.Web.dll, and then click Select.  
c.  Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries you selected, click Yes.

Though I do not need to add it in my Application somehow..

-tushar
0
 
PaulHewsConnect With a Mentor Commented:
Go into references for your project and add a reference to System.Web.DLL

Dont give me any points, just helping out on this one.
0
 
JohnnyAuthor Commented:
     
it does not like line

System.Web.Mail.SmtpMail.Send()

Error      1            Overload resolution failed because no accessible 'Send' accepts this number of arguments.

we where missing the
Add a reference to System.Web.dll. To do this, follow these steps:a.  On the Project menu, click Add Reference.
b.  On the .NET tab, locate System.Web.dll, and then click Select.  
c.  Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries you selected, click Yes.


now we only have the one error
getting closer
                  
0
 
tusharashahCommented:
System.Web.Mail.SmtpMail.Send()

Requires MailMessage object as argumnet

System.Web.Mail.SmtpMail.Send( msg )

-tushar
0
 
JohnnyAuthor Commented:
works now

thx alot...

tusharashah would you mind if give 5 points to PaulHews as PaulHews was right about the refrence

i know PaulHews said no points but im fair..

thx again

and thats reall good looking girl JOY came back in the bulding..and kissed you!! (smile)
0
 
tusharashahCommented:
:)

oh yes.. i dont mind even if you give all points to him..

i've got my points

-tushar
0
 
PaulHewsCommented:
I only posted because it looked like you were having problems figuring out the reference, but even then tushar posted that solution before me, so really no points necessary here.  Tushar stuck with you from the beginning...
0
 
JohnnyAuthor Commented:
min was 20 thx alot again
0
 
PaulHewsCommented:
So thanks anyway... :)
0
All Courses

From novice to tech pro — start learning today.