[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how do i send an email to a user via code

Posted on 2004-10-23
34
Medium Priority
?
247 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Johnny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 14
  • 3
34 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390074
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
 

Author Comment

by:Johnny
ID: 12390110
VB.Net
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390116
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Johnny
ID: 12390242
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
 

Author Comment

by:Johnny
ID: 12390261
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
 

Author Comment

by:Johnny
ID: 12390263
thx for the nifty property discrip too
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390294
I mentioned that in my lastpost:

You'll need

System.Web.Mail

-tushar
0
 

Author Comment

by:Johnny
ID: 12390313
my fault sorry
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390323
Oh dont worry, that happens.. post back if you got it working :>
0
 

Author Comment

by:Johnny
ID: 12390326
     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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390345
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
 

Author Comment

by:Johnny
ID: 12390374
     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
 

Author Comment

by:Johnny
ID: 12390380
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390430
hmmm.. damn..

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

-tushar
0
 

Author Comment

by:Johnny
ID: 12390439
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390460
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
 

Author Comment

by:Johnny
ID: 12390468
     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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390479
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390485
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
 

Author Comment

by:Johnny
ID: 12390487
     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
 

Author Comment

by:Johnny
ID: 12390495
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
 

Author Comment

by:Johnny
ID: 12390505
nope no IIS
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1920 total points
ID: 12390506
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
 

Author Comment

by:Johnny
ID: 12390513
it look as you said... and did that in l;ast message

and thx for your persistance im inpressed
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390527
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390535
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
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 80 total points
ID: 12390542
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
 

Author Comment

by:Johnny
ID: 12390551
     
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390563
System.Web.Mail.SmtpMail.Send()

Requires MailMessage object as argumnet

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

-tushar
0
 

Author Comment

by:Johnny
ID: 12390596
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12390603
:)

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

i've got my points

-tushar
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 12390608
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
 

Author Comment

by:Johnny
ID: 12390612
min was 20 thx alot again
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 12390613
So thanks anyway... :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question