jmail群发邮件
小弟请教高人:
jmail群发邮件,最好帖出来一段原码,搜了n长时间后怀疑:我真逊?还是好多代码逊
(高人别见笑,小弟初来论坛,人生地不熟!!!)
[解决办法]
HTML:
--------------------
<form id= "Form1 " method= "post " runat= "server ">
<FONT face= "宋体 ">
<TABLE id= "Table1 " style= "Z-INDEX: 101; LEFT: 200px; WIDTH: 496px; POSITION: absolute; TOP: 120px; HEIGHT: 208px "
cellSpacing= "1 " cellPadding= "1 " width= "496 " border= "5 ">
<TR>
<TD align= "center " colSpan= "3 "> <asp:label id= "Label1 " runat= "server " Font-Size= "Large " Font-Bold= "True " ForeColor= "Red "> 发送邮件 </asp:label> </TD>
</TR>
<TR>
<TD> <asp:label id= "Label6 " runat= "server " Font-Bold= "True "> 发件标题: </asp:label> </TD>
<TD> <asp:textbox id= "titletxt " runat= "server " MaxLength= "20 " Height= "24 " Width= "219 "> </asp:textbox> </TD>
<TD> <asp:requiredfieldvalidator id= "RequiredFieldValidator5 " runat= "server " ControlToValidate= "titletxt " ErrorMessage= "* "> </asp:requiredfieldvalidator> </TD>
</TR>
<TR>
<TD style= "HEIGHT: 11px "> <asp:label id= "Label2 " runat= "server " Font-Bold= "True "> 收件人地址: </asp:label> </TD>
<TD style= "HEIGHT: 11px "> <asp:textbox id= "toemail " runat= "server " Height= "24px " Width= "219px "> </asp:textbox> </TD>
<TD style= "HEIGHT: 11px "> <asp:requiredfieldvalidator id= "RequiredFieldValidator1 " runat= "server " ControlToValidate= "toemail " ErrorMessage= "* "> </asp:requiredfieldvalidator> <asp:regularexpressionvalidator id= "RegularExpressionValidator1 " runat= "server " ControlToValidate= "toemail " ErrorMessage= "请填写正确邮箱 "
ValidationExpression= "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* "> </asp:regularexpressionvalidator> </TD>
</TR>
<TR>
<TD style= "HEIGHT: 3px "> <asp:label id= "Label3 " runat= "server " Font-Bold= "True "> 发件人地址: </asp:label> </TD>
<TD style= "HEIGHT: 3px "> <asp:textbox id= "fromemailtxt " runat= "server " Height= "24px " Width= "219px "> </asp:textbox> </TD>
<TD style= "HEIGHT: 3px "> <asp:requiredfieldvalidator id= "RequiredFieldValidator2 " runat= "server " ControlToValidate= "fromemailtxt " ErrorMessage= "* "> </asp:requiredfieldvalidator> <asp:regularexpressionvalidator id= "RegularExpressionValidator2 " runat= "server " ControlToValidate= "fromemailtxt "
ErrorMessage= "请填写正确邮箱 " ValidationExpression= "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* "> </asp:regularexpressionvalidator> </TD>
</TR>
<TR>
<TD style= "HEIGHT: 71px "> <asp:label id= "Label5 " runat= "server " Font-Bold= "True "> 发件内容: </asp:label> </TD>
<TD style= "HEIGHT: 71px "> <asp:textbox id= "message " runat= "server " MaxLength= "1000 " Height= "70px " Width= "219px " TextMode= "MultiLine "> </asp:textbox> </TD>
<TD style= "HEIGHT: 71px "> <asp:requiredfieldvalidator id= "RequiredFieldValidator4 " runat= "server " ControlToValidate= "message " ErrorMessage= "* "> </asp:requiredfieldvalidator> </TD>
</TR>
<TR>
<TD style= "HEIGHT: 9px "> <asp:label id= "Label4 " runat= "server " Font-Bold= "True "> 发件人密码: </asp:label> </TD>
<TD style= "HEIGHT: 9px "> <asp:textbox id= "fromemailpwd " runat= "server " Height= "24px " Width= "219px " TextMode= "Password "> </asp:textbox> </TD>
<TD style= "HEIGHT: 9px "> <asp:requiredfieldvalidator id= "RequiredFieldValidator3 " runat= "server " ControlToValidate= "fromemailpwd " ErrorMessage= "* "> </asp:requiredfieldvalidator> </TD>
</TR>
<TR>
<TD> </TD>
<TD> <asp:button id= "sendbtn " runat= "server " Text= "发送邮件 "> </asp:button> </TD>
<TD> <asp:label id= "lblmessage " runat= "server " Font-Bold= "True " ForeColor= "Red "> </asp:label> </TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
[解决办法]
JMail组件的常用方法:
AddAttachment 指定附件文件
AddRecipient 加入一个收件人
AddRecipientBCC 隐藏的副本抄送,只有发件人和BCC收件人知道。
AddRecipientCC 副本抄送
Execute 送出邮件
了解必要的属性及方法后,余下的部分接收使用者输入的Email,当成参数传给AddRecipient方法,然后根据需要填上其余属性,最后以Execute方法寄出。例如:
JMail = Server.CreateObject( "JMail.SMTPMail ")
JMail.Logging = True
JMail.ServerAddress = "202.96.144.48 "
JMail.Sender = "lihonggen0@163.com "
JMail.Subject = "subject. "
JMail.Body = "body. "
JMail.AddRecipient( "bbbb@163.com ")
JMail.AddAttachment( "c:\go.gif ")
JMail.Priority = 3
JMail.Execute()
JMail = Nothing
[解决办法]
如果你用system.net的话..就方便了!!只要注意一点.你的163的邮箱如果是2005年之后申请的话不能用!还不如用QQ邮箱:
代码如下:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mg As MailMessage = New MailMessage()
mg.From = New MailAddress( "chuxue1342@qq.com ") '发件人邮箱
mg.To.Add( "chuxue1342@avl.com.cn ") '收件人邮箱
mg.Subject = "邮件测试 " '邮件主题
mg.Body = "测试邮件,,内容为空 " '邮件内容
mg.BodyEncoding = System.Text.Encoding.UTF8 '内容编码
mg.IsBodyHtml = True '是否支持HTML格式
mg.Priority = MailPriority.High '优先级别
mg.Attachments.Add(New Attachment( "c:\ps.txt ")) '添加附件
Dim smtp As SmtpClient = New SmtpClient()
smtp.DeliveryMethod = SmtpDeliveryMethod.Network '邮件发送方式.这里通过网络
smtp.Host = "smtp.qq.com " '邮件发送服务器
smtp.Credentials = New NetworkCredential( "113620916 ", "****** ") '用户名跟密码
Try
smtp.Send(mg)
Label2.Text = "OK "
Catch ex As Exception
Label2.Text = ex.ToString
End Try
End Sub