Recently, a small system needs to be developed, where the system uses the automatically generated password to send the client's email address. Previously, ASP + jmail4.4 was used for operations, this time the system was executed on Windows 2003 + Asp.net + SQL Server 2005, so we thought of using jmail.net for sending.
After downloading jmail.net 1.1, I simply checked the routine and started to work. Although it was very simple, I recorded the process. Please share it with us.
Set dimac. jmail. DLL and dimac. jmail. SMTP. DLL file to the bin directory, run the SMTP. on the ASPX page, you can send an email to yourself. The email is successfully sent, and there are several problems encountered during this period:
1. "An exception occured: 530 authentication required" indicates that the SMTP server needs to be verified and "authentication:" indicates that a verification method is required;
2. "An exception occured: Plain is not supported". This error is reported when the authentication method is "plain". This error is caused by SMTP server's failure to support plain authentication, I checked some information on the Internet and learned that the plain authentication method is plain text sending verification, while the login authentication method is base64 encrypted file verification. It seems that the SMTP server has a high security setting, after "login" is selected, you can use "any". I still don't know if any is used to loop through various verification methods?
SMTP authentication method documents: http://hi.baidu.com/%B6%AC%D2%E2%BE%D3/blog/item/a06518fbf646802e4f4aea99.html
3. "An exception occured: 554 sender address not allowed for this authenticated session", because an address I entered in the "from" is not in the authentication list, it seems to be a security restriction on the server. You must enter a valid email address and use the same username and password as used for verification to prevent counterfeit emails. This should be related to the SMTP server, and has little to do with jmail.net itself.
After sending the message, I want to modify it so that I can call it on other pages. Now I will share the Code with you:
Create a new class in app_code named sendmail. VB
Imports Microsoft. visualbasicimports systemimports dimac. jmailpublic class Sendmail function Sendmail (byval sendname as string, byval toemail as string, byval toname as string, byval mailsubject as string, byval mailbody as string, byval mailhtml as Boolean) as Boolean dim message as new dimac. jmail. message () 'sending address. Here I use a fixed address message. from. email = "it@mycompany.com" message. from. fullname = sendname' recipient message. to. add (toemail, toname) 'topic message. subject = mailsubject 'character set, which is now directly specified as gb2312 message. charset = system. text. encoding. getencoding ("gb2312") 'selects whether to send if mailhtml then message in HTML or text format. bodyhtml = mailbody else message. bodytext = mailbody end if try 'smtp server authentication method dim selected = [Enum]. parse (GetType (smtpauthentication), "login") 'uses a single sending method, you can also assign values to each item and then send the following parameters: Mail content, SMTP server address, SMTP Service port, Host Name (content following @), and verification method, verify the user name and password SMTP. send (message, "192.168.1.30", 25, "mycompany.com", selected, "it", "it123") return true catch ex as exception 'response. write (ex. message) return false end try end functionend class
The parameters of the Sendmail function are respectively the sender name, recipient address, recipient name, email subject, email content, and whether HTML format is used.
Create a test page and call the following code:
Test. aspx
<% @ Page Language = "VB" autoeventwireup = "false" codefile = "test. aspx. VB" inherits = "test" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Test. aspx. VB
Imports SystemImports SendMailPartial Class test Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sendmail1 As New SendMail sendmail1.SendMail(TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox1.Text, chk_html.Checked) End SubEnd Class
The test is successful. However, if you select HTML format and HTML code on the test page, IIS reports an error saying that there are insecure characters, this can be controlled in actual use or implemented in post mode.