Solved

show the mail before sending

Posted on 2006-07-23
19
301 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:ANAT2403
  • 11
  • 5
  • 3
19 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17162812
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
0
 
LVL 23

Expert Comment

by:apresto
ID: 17162813
What code do you have at the moment for the page
0
 

Author Comment

by:ANAT2403
ID: 17162873
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

0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 23

Expert Comment

by:apresto
ID: 17162904
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
0
 

Author Comment

by:ANAT2403
ID: 17162927
But all this will not appear as mail.
I want it to appear as mail in outlook
Anat
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17162953
Do you want to integrate with Outlook, or have a web page that resembles the Outlook mail item form?

Bob
0
 

Author Comment

by:ANAT2403
ID: 17163050
I would like to integrate with Outlook.
Anat
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163054
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
0
 

Author Comment

by:ANAT2403
ID: 17163062
Any how how I do it through Outlook?
Anat
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163080
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
0
 

Author Comment

by:ANAT2403
ID: 17163093
The thing is that in some mails I have to send it automatically with the SMTP and in some mails through the outlook.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163103
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
0
 

Author Comment

by:ANAT2403
ID: 17183517
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?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17183648
Try this:

public static void SendMail(string toAddress, string subject, string body, string attachment)
{
    Outlook.Application app = new Outlook.Application()
    Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem);
    mail.To = toAddress;
    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);

}

Bob
0
 

Author Comment

by:ANAT2403
ID: 17184119
I can't write the Outlook.Application. It is not recognized. I need some namespace. You know which one?
Anat
0
 

Author Comment

by:ANAT2403
ID: 17184225
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
0
 

Author Comment

by:ANAT2403
ID: 17184988
mail.Display() force me to give a parameter.  (oject Modal)
What parameter can I give?

 
0
 

Author Comment

by:ANAT2403
ID: 17185219
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?
0
 

Author Comment

by:ANAT2403
ID: 17185301
Ok I ask the question and answer them.
In the display i had to write display(true)
OK it works OK.
Thankyou
Anat
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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