90% exchange mail management developed using WebDAV (5)
-- The remaining 10% is used for sending emails.
In the above article, I know the basic format of the mail, but I still have no way to use WebDAV to construct an email with an attachment. Although the basic idea is as follows: UseCodeGenerate randomBoundaryString, and then convert the uploaded file to base64 encoding, and attach it to the email. However, the attempt was unsuccessful. Later, I found on a blog that I needed to construct a text email body. Then I sent an email and asked, but no response was received. It should be because my English is too bad. This is the only time I did not reply to my questions like a foreigner. Unlike a VIP, The remoting client commissionedArticleThe example does not run at all, (basically none of the Code that allows deserialization) and does not return emails.
1. send an email
Finally, we use CDO for this part, so the title is 90%. The process is as follows:
1. Add a reference to the CDO component.
2. Code:
Try
{
CDO. messageclass mail = New CDO. messageclass ();
Mail. = This . TBTO. text;
Mail. CC = This . Tbcc. text;
Mail. bcc = This . Tbbcc. text;
Mail. Subject = This . Tbsubject. text;
Mail. From = User. Identity. Name;
Mail. textbody = This . Freetextbox1.text;
String Userid = User. Identity. Name. Trim ();
String Strpassword = Dal. Data. usermodel. selectbyuserid (userid). Password. Trim ();
String [] Filename = This . Tbattachment. value. tostring (). Split ( New Char [] {','} );
Foreach ( String S In Filename)
{
If (S ! = String. Empty)
{
Mail. addattachment (server. mappath ("Mailattachment/"+S), userid, strpassword );
}
}
Mail. Send ();
Response. Write ( " <SCRIPT> alert (\ " Email sent successfully \ " ) </SCRIPT> " );
}
Catch (Exception ex)
{
Response. Write ("<SCRIPT> alert (\""+ Ex. Message +"\") </SCRIPT>");
}
This Code does not have any problems during debugging, but when it is deployed on another machine, a new problem occurs and the following content is introduced.
Ii. CDO. Configuration
When the system is deployed, the system prompts "sendusing error" when an email is sent. Exchange was not installed on my machine at the beginning, and the code written can run, but I don't know where the email is sent. On the machine where exchange is installed, exchange is sent from the local machine. I personally think, specifically, it is an exchange server in the same domain as the web server. So how does CDO. dll work?
Cdopostusing has these two enumerated values, see SDK. http://msdn2.microsoft.com/en-us/library/ms527265.aspx for details
Cdosendusingpickup |
1 |
Send message using the local SMTP service pickup directory. |
Cdosendusingport |
2 |
Send the message using the Network (SMTP over the network ). |