asp .net附件发送问题(100分)

  • 主题发起人 主题发起人 xddouble
  • 开始时间 开始时间
X

xddouble

Unregistered / Unconfirmed
GUEST, unregistred user!
asp .net附件发送问题:发送桌面文件出错,发送其他地方文件无错,请解答,本人用vs.net2003.
private void Btn_Send_Click(object sender, System.EventArgs e)
{
int returnint = 0;
returnint = Convert.ToInt32( FunClass.SendMail(Page,TBmailTo.Text.Trim(), TBmailSubject.Text, TBmailCC.Text,Ftb_mailBody.Text ,upFile.PostedFile.FileName));
if(returnint == 0)
{
FunClass.ShowMessage(Page,"邮件发送失败!");
}
else
{
FunClass.ShowMessage(Page,"邮件已发送到"+TBmailTo.Text);
}
}
public int SendMail(Page pPage,string pToMail,string pSubject,string pCC,string pBody,string pUpfile)
{
try
{
MailMessage mailObj = new MailMessage();
mailObj.From = "xddouble@126.com";
mailObj.To = pToMail;
mailObj.Cc = pCC;
mailObj.Subject = pSubject;
mailObj.Body = pBody;
mailObj.BodyFormat = MailFormat.Text;

mailObj.Priority = MailPriority.High;

if(pUpfile.ToString() != String.Empty ||pUpfile.ToString() !="")
{
mailObj.Attachments.Add(new MailAttachment(pUpfile));
}
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthen
ticate", "1");
//basic authen
tication
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxxx");
//set your username here
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxx");
//set your password here
SmtpMail.SmtpServer = "smtp.126.com";

SmtpMail.Send(mailObj);
return 1;
}
catch
{
return 0;
}
}
 
建议使用JMail。。。。
用Jmail发送附件:
jmail.Body="this is a file from jmail using c# asp.net";

jmail.AddAttachment(Server.MapPath("01.jpg"),false,"image/jpg");

发送HTML:
jmail.HTMLBody=&quot;<hr>this is html<br>&quot;;

如果HTML内容中含有图像等连接,可以:
1)
jmail.HTMLBody=&quot;<hr>this is html<br><img src=http://www.image.com/img.gif'>&quot;;

2)
string cid=jmail.AddAttachment(Server.MapPath(&quot;01.jpg&quot;),true,&quot;image/jpg&quot;);

jmail.HTMLBody=&quot;<hr>this is html<br><img src='cid:&quot;+cid+&quot;'>&quot;;

===========我在网上找的一个顺便也给你------
怎么用JMAIL发送附件?
内容:
用ASP怎么写?
回复:
up
回复:
http://www.sron.net/art/article.php?articleid=313
(1)Body(信件正文) : 字符串
如:JMail.Body = &quot;这里可以是用户填写的表单内容,可以取自From。&quot;
(2)Charset(字符集,缺省为&quot;US-ASCII&quot;) : 字符串
如:JMail.Charset = &quot;US-ASCII&quot;
(3)ContentTransferEncoding : 字符串
指定内容传送时的编码方式,缺省是&quot;Quoted-Printable&quot;
如:JMail.ContentTransferEncoding = &quot;base64&quot;
(4)ContentType(信件的contentype. 缺省是&quot;text/plain&quot;) : 字符串
如果你以HTML格式发送邮件, 改为&quot;text/html&quot;即可。
如:JMail.ContentType = &quot;text/html&quot;
(5)Encoding : 字符串
设置附件编码方式(缺省是&quot;base64)。 可以选择使用的是&quot;base64&quot;, &quot;uuencode&quot;
or &quot;quoted-printable&quot;
如:JMail.Encoding = &quot;base64&quot;
(6)Log(Jmail创建的日志,前提loging属性设置为true,见下面) : 字符串
如:使用Response.Write( JMail.Log )语句列出日志信息。
(7)Logging(是否使用日志) : 布尔型
如:JMail.Logging = true
(8)Recipients : 字符串
只读属性,返回所有收件人
如:Response.Write( &quot;&quot;
+ JMail.Recipients + &quot;&quot;
);
(9)ReplyTo(指定别的回信地址) : 字符串
如:JMail.ReplyTo = &quot;anyother@mailhost.com&quot;
(10)Sender( 发件人的邮件地址) : 字符串
如:JMail.Sender = &quot;sender@mailhost.com&quot;
(11)SenderName(发件人的姓名) : 字符串
如:JMail.SenderName = &quot;一克&quot;
(12)ServerAddress(邮件服务器的地址) : 字符串
你可以指定多个服务器,用分号点开。可以指定端口号。
如果serverAddress保持空白,JMail会尝试远程邮件服务器,然后直接发送到服务器上去。
如:JMail.ServerAddress = &quot;mail.263.net.cn&quot;
(13)Subject(设定邮件的标题,可以取自From。):字符串
如:JMail.Subject = &quot;客户反馈表单&quot;
(14)添加文件附件到邮件
如:JMail.AddAttachment( &quot;c:/anyfile.zip&quot;
)
(15)AddCustomAttachment( FileName, Data )
添加自定义附件.
如:JMail.AddCustomAttachment( &quot;anyfile.txt&quot;, &quot;Contents of file&quot;
);
(16)AddHeader( Header, Value )
添加用户定义的信件标头。
如:JMail.AddHeader( &quot;Originating-IP&quot;,&quot;192.168.10.10&quot;
);
(17)AddRecipient(收件人):字符串
如:JMail.AddRecipient( &quot;info@dimac.net&quot;
);
(18)AddRecipientBCC( Email ),密件收件人:
如:JMail.AddRecipientBCC( &quot;anyone@mailhost.com&quot;
);
(19)AddRecipientCC( Email ) ,抄送收件人:
如:JMail.AddRecipientCC( &quot;anyone@mailhost.com&quot;
)
(20)AddURLAttachment( URL, 文档名)
下载并添加一个来自url的附件. 第二个参数&quot;文档名&quot;, 用来指定信件收到后的文件名。
如:JMail.AddURLAttachment( &quot;http://www.chinabs.net/jmail.zip&quot;, &quot;jmail&quot;
)
(21)AppendBodyFromFile( 文件名) ,将文件作为信件正文:
如:JMail.AppendBodyFromFile( &quot;c:/anyfile.txt&quot;
)
(22)AppendText( Text )
追加信件的正文内容,比如增加问候语或者其它信息。
如:JMail.AppendText( &quot;欢迎访问本站!&quot;
)
(23)Close() ,强制JMail关闭缓冲的与邮件服务器的连接:
如:JMail.Close()
(24)Execute() ,执行邮件的发送
如:JMail.Execute()

下面是本站忘记密码时的程序代码,现在共享出来让大家学习:
path=Server.MapPath(&quot;/images/logo.gif&quot;)
Set JMail=Server.CreateObject(&quot;JMail.SMTPMail&quot;)
JMail.ContentType=&quot;text/html&quot;
JMail.Encoding = &quot;base64&quot;
JMail.Charset=&quot;gb2312&quot;
JMail.ServerAddress = &quot;mail.chinabs.net&quot;
JMail.Sender = &quot;chinabs@chinabs.net&quot;
JMail.Subject = &quot;chinabs.net发给您的密码!&quot;
JMail.AddRecipient(email)
JMail.Body =str
JMail.AddHeader &quot;Originating-IP&quot;, Request.ServerVariables(&quot;REMOTE_ADDR&quot;)
JMail.AddAttachment(path)
JMail.Execute
JMail.Close
Set JMail = Nothing
 
后退
顶部