ANAT2403
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.MailMessag e message = new System.Net.Mail.MailMessag e(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
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
MailAddress from = new MailAddress("anat@business
System.Net.Mail.MailMessag
message.Subject = "test email1";
message.Body = "test email1 from business-solutions on 18/06/2006";
System.Net.Mail.SmtpClient
smtp.Send(message);
Thankyou
Anat
What code do you have at the moment for the page
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
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
You dont need to use response.write - you could populate a literal control or some other web control with the message body
Apresto
ASKER
But all this will not appear as mail.
I want it to appear as mail in outlook
Anat
I want it to appear as mail in outlook
Anat
Do you want to integrate with Outlook, or have a web page that resembles the Outlook mail item form?
Bob
Bob
ASKER
I would like to integrate with Outlook.
Anat
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
Bob
ASKER
Any how how I do it through Outlook?
Anat
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.OlI temType.ol MailItem)
mail.To = [to]
mail.Subject = subject
mail.BodyFormat = Outlook.OlBodyFormat.olFor matRichTex t
mail.Body = body
mail.Display()
app.Quit()
System.Runtime.InteropServ ices.Marsh al.Release ComObject( app)
System.Runtime.InteropServ ices.Marsh al.Release ComObject( 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
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.OlI
mail.To = [to]
mail.Subject = subject
mail.BodyFormat = Outlook.OlBodyFormat.olFor
mail.Body = body
mail.Display()
app.Quit()
System.Runtime.InteropServ
System.Runtime.InteropServ
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
ASKER
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
Bob
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I can't write the Outlook.Application. It is not recognized. I need some namespace. You know which one?
Anat
Anat
ASKER
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
OK I undesrtood. I have to add Reference to COM Microsoft Outlook 11.0 Object Library.
I will continue now and inform you.
Anat
ASKER
mail.Display() force me to give a parameter. (oject Modal)
What parameter can I give?
What parameter can I give?
ASKER
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?sub ject=Your subject&to=anat@business-s olutions.c o.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?
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
in the code behind so that I can give values to the body ,to and subject.
How do I do it?
ASKER
Ok I ask the question and answer them.
In the display i had to write display(true)
OK it works OK.
Thankyou
Anat
In the display i had to write display(true)
OK it works OK.
Thankyou
Anat
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
MailAddress from = new MailAddress("anat@business
System.Net.Mail.MailMessag
message.Subject = "test email1";
message.Body = "test email1 from business-solutions on 18/06/2006";
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