asp.Net送信メールの例共有
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mail;
///
///mailhelper
///
public class mailhelper
{
public mailhelper()
{
//
//TODO:
//
}
///
///
///
///
///
///
///
///
///
///
///
public string SendeEmal(string Addressee, string From, string sendpassword, string Copy, string secret, string Subject, string Attachment, string Body)
{
MailMessage objMailMessage;
MailAttachment objMailAttachment;
//
objMailMessage = new MailMessage();
// EMAIL
objMailMessage.From = From;//
// EMAIL
objMailMessage.To = Addressee; //
//
objMailMessage.Cc = Copy;
// misong
objMailMessage.Bcc = secret;
//
objMailMessage.Subject = Subject; //
//
objMailMessage.Body = Body;//
//
if (Attachment != "")
{
objMailAttachment = new MailAttachment(Attachment);// c:\\test.txt
objMailMessage.Attachments.Add(objMailAttachment);//
}
// SMTP , Microsoft .NET Framework SDK v1.1
//
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//
string name = From.Substring(0, From.IndexOf('@'));
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", name);
//
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendpassword);
// , : 。 : 554 : Client host rejected: Access denied
//SMTP
string smtp = "smtp." + From.Substring(From.IndexOf('@') + 1);
SmtpMail.SmtpServer = "smtp." + From.Substring(From.IndexOf('@') + 1);
//
try
{
SmtpMail.Send(objMailMessage);
return " !";
}
catch (System.Net.Mail.SmtpException ex)
{
return ex.Message;
}
//
}
}
次は自分で作ったdemoです
フロント
ValidateRequest="false" %>
<br/> <script src="../Style/jquery/jquery.js" type="text/javascript"/><br/> <script src="../Style/jquery/jquery.validate.js" type="text/javascript"/><br/> <script language="javascript" type="text/javascript">
<p> function gei() {<br> var file_value = document.getElementById("File1").value;<br> document.getElementById("HiddenField1").value = file_value;<br> }<br> </script><br/><br/><br/> <form id="form1" runat="server"><br/> <div><br/> :<textbox id="TextBox1" runat="server"/><br/><br/> :<textbox id="TextBox2" runat="server"/><br/><br/> :<textbox id="TextBox4" runat="server"/><br/><br/> :<textbox id="TextBox5" runat="server"/><br/><br/> :<textbox id="TextBox3" runat="server"/><br/><br/> :<input id="File1" type="file"/><br/> --%><br/> <br/><br/> <button id="Button1" runat="server" text=" " onclientclick="gei()" onclick="Button1_Click"/><br/><br/> <label id="Label1" runat="server" text=""/><br/> </div><br/> <hiddenfield id="HiddenField1" runat="server"/><br/> </form><br/><br/><br/>
</code></pre>
<br/>
<br/> :
<br/>
<pre><code>
<br/>protected void Button1_Click(object sender, EventArgs e)
<br/> { //
<br/> mailhelper mails = new mailhelper();
<p> string filePath = HiddenField1.Value;</p>
<p> string a = mails.SendeEmal(TextBox1.Text, " ", " ", TextBox2.Text, TextBox4.Text, TextBox5.Text, filePath, TextBox3.Text);</p>
<p> Label1.Text = a;<br/>}<br/></p>
</code></pre>
<div class="clearfix">
<span id="art_bot" class="jbTestPos"/>
</div>
</div>
</div>
</div>