Link to home
Start Free TrialLog in
Avatar of ANAT2403
ANAT2403Flag for Israel

asked on

show the mail before sending

In ASP.NET 2.0 in C#
I prepare a mail to be send with all that is needed
but I don't want to send it automatically.
I want to show the mail on the screen, to let the user check it and then
the user will press the button of send.
This is my preparing of the mail. What do I have to change?
   
           MailAddress to = new MailAddress("anat@business-solutions.co.il");
            MailAddress from = new MailAddress("anat@business-solutions.co.il");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);

            message.Subject = "test email1";
            message.Body = "test email1 from business-solutions on 18/06/2006";
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
             smtp.Send(message);
Thankyou
Anat
Avatar of apresto
apresto
Flag of Italy image

Hi ANAT2403,

What you could do is create the message object with page scope and do this in the page_load event:

MailAddress to = new MailAddress("anat@business-solutions.co.<wbr/>il");
            MailAddress from = new MailAddress("anat@business-solutions.co.<wbr/>il");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);

            message.Subject = "test email1";
            message.Body = "test email1 from business-solutions on 18/06/2006";
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            Response.Write( message.Body );

then have a button on the page, that when clicked that sends it with:

smtp.Send(message);

Apresto
What code do you have at the moment for the page
Avatar of ANAT2403

ASKER

Hi Apresto
This situation might happen while I have various codes in a page. I guess I should open a new page for this
because the response.write will overwrite the content of my page
Why did you say to put it in the page_load event?
Thanks
Anat

I just said page_load as an example, i meant put it somewhere where it would load when the page did, as i assumed that the information to be used in the message obvject would be submitted to this page from another.

You dont need to use response.write - you could populate a literal control or some other web control with the message body

Apresto
But all this will not appear as mail.
I want it to appear as mail in outlook
Anat
Avatar of Bob Learned
Do you want to integrate with Outlook, or have a web page that resembles the Outlook mail item form?

Bob
I would like to integrate with Outlook.
Anat
That is a messy proposition, since Outlook is COM, and by its very nature a single threaded environment, while ASP.NET is multi-threaded.  You need to be very certain that you can't accomplish this another way before going down the Outlook road.

Bob
Any how how I do it through Outlook?
Anat
1) You need Outlook installed on a server, if you are publishing from a machine to a remote machine

2) You need to add a COM reference for the Microsoft Outlook type library to the project

3) Use something like this:

  Public Shared Sub SendMail(ByVal [to] As String, ByVal subject As String, ByVal body As String, ByVal attachment As String)

    Dim app As New Outlook.Application
    Dim mail As Outlook.MailItem = app.CreateItem(Outlook.OlItemType.olMailItem)
    mail.To = [to]
    mail.Subject = subject
    mail.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
    mail.Body = body
    mail.Display()

    app.Quit()

    System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
    System.Runtime.InteropServices.Marshal.ReleaseComObject(mail)

  End Sub

4) Depending on the version of Outlook, and the COM wrapper that gets generated, you might have to fix that example code.

5) If you use Outlook, then you don't need all that SMTP stuff

Bob
The thing is that in some mails I have to send it automatically with the SMTP and in some mails through the outlook.
Ok, I am not trying to dictate any course of action.  I assumed that you were replacing SMTP with Outlook.  If you need both, then keep it.

Bob
Hi,
I want to use the code you sent me for opening the outlook but I need it in C# and I don't succeed
to tranform it to C#. I guess I need some using namespaces in the beginning.
Can you help?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can't write the Outlook.Application. It is not recognized. I need some namespace. You know which one?
Anat
Hi,
OK I undesrtood. I have to add Reference to COM Microsoft Outlook 11.0 Object Library.
I will continue now and inform you.
Anat
mail.Display() force me to give a parameter.  (oject Modal)
What parameter can I give?

 
Hi,
It sends the mail but it does not open the outlook . I want to open the outlook see the prepared mail, approve it
and then send it by pressing the send button of the outlook.
I would like to main the command
<a href="mailto:anat@business-solutions.co.il?subject=Your subject&to=anat@business-solutions.co.il&body=Enter your message here">Mail</a>
in the code behind so that I can give values to the body ,to and subject.
How do I do it?
Ok I ask the question and answer them.
In the display i had to write display(true)
OK it works OK.
Thankyou
Anat