Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2006, 10:19 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with email code

Basically all I want to do this take the applicant email address out and from the txtEmailAddress.Text field and sent them an automatic response. The code is below but im getting some compile errors. Anyone know how to fix it or have code to do what I want to do.

 SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
            MailAddress toAddress = new MailAddress(txtEmailAddress.Text);
            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost
            smtpClient.Host = "www.colaistenamumhan.ie";

            //Default port will be 25
            smtpClient.Port = 25;

            //From address will be given as a MailAddress Object
            message.From("Moluasaigh@gmail.com");

            // To address collection of MailAddress
            message.To = toAddress;
            message.Subject = "Foirm Iarratais - Booking Form";

            //Body can be Html or text format
            //Specify true if it is html message
            //message.IsBodyHtml = false;

            // Message body content
            message.Body = "Your details have been entered into the database. We will contact you shortly, once your details have been verified and processed. Tá do chuid sonraí againn anois. Beifear i dteagmháil leat a luaithe agus a bheidh do fhoirm iarrtais fíoraithe. Is mór againn gur roghnaigh tú Coláiste na Mumhan. Taímíd ag tnúth le tú a fheiscint i mBéal Átha an Ghaorthaidh. Bain TAITNEAMH agus TAIRFE as do chuairt. We appreciate your choosing Coláiste Na Mumhan. We look forward to meeting you. GO RAIBH MAITH AGAT.";

            // Send SMTP mail
            smtpClient.Send(message);

            lblStatus.Text = "Email successfully sent.";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Send Email Failed." + ex.Message;
        }
 
Old March 3rd, 2006, 10:27 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are the compile errors?

- A.Kahtava
 
Old March 3rd, 2006, 10:34 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These are the three errors:
 message.From("Moluasaigh@gmail.com");
message.To = toAddress;
 
Old March 3rd, 2006, 10:36 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I should also say the errors are in relation to message.From("Moluasaigh@gmail.com"); are about property being used as a string

message.To = toAddress; this it says is a read only and cant convert the type also shows up here.
 
Old March 3rd, 2006, 10:45 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are assigning MailAddresses incorrectly.

An Example:
    MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
    MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
    MailAddress copy = new MailAddress("Notification_List@contoso.com");

Take a look at the MailAddress Class: http://msdn2.microsoft.com/en-us/lib...iladdress.aspx

- A.Kahtava
 
Old March 3rd, 2006, 10:49 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In your case you might use something like:
message.From = new MailAddress("Moluasaigh@gmail.com");

- A.Kahtava
 
Old March 3rd, 2006, 10:49 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how do I set the MailAddress to = a textbox
 
Old March 3rd, 2006, 10:55 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Download and browse through the source code for this project, setting MailAddress to a textbox should be self explanatory.

Send Email in ASP.Net 2.0 - Feed back Form: http://www.codeproject.com/useritems...pplication.asp

- A.Kahtava
 
Old March 3rd, 2006, 10:58 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million. Your help is much appreciated. Wish I had all the knowledge you have in relation to these matters. Thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Email Attachment Code kunal_shiradkar SQL Server 2000 1 March 27th, 2007 09:59 AM
code for Sending Email in jsp mhadz JSP Basics 0 January 12th, 2007 03:55 AM
email code.. rupen Classic ASP Basics 8 January 4th, 2007 09:55 AM
Changing Email Code hoffmann Classic ASP Basics 7 November 3rd, 2006 09:22 AM
sending email in code xchemicalbeatz VB.NET 2002/2003 Basics 12 June 3rd, 2005 01:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.