次のようにaspでメールを送信しています:
MailMessage msg = new MailMessage();
msg.From = new MailAddress("from@email", "From Name");
msg.Subject = "Subject";
msg.To.Add("to@email");
msg.BodyEncoding = Encoding.UTF8;
String plainBody = "Body of plain email";
AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainBody, Encoding.UTF8, "text/plain");
msg.AlternateViews.Add(plainView);
//now create the HTML version
MailDefinition message = new MailDefinition();
message.BodyFileName = "~/MailTemplates/template1.htm";
message.IsBodyHtml = true;
message.From = "from@email";
message.Subject = "Subject";
ListDictionary replacements = new ListDictionary();
replacements.Add("<%USERNAME%>", "ToUsername");//example of dynamic content for Username
MailMessage msgHtml = message.CreateMailMessage("to@email", replacements, new LiteralControl ());
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(msgHtml.Body, Encoding.UTF8, "text/html");
LinkedResource imgRes = new LinkedResource(Server.MapPath("~/MailTemplates/images/imgA.jpg"), System.Net.Mime.MediaTypeNames.Image.Jpeg);
imgRes.ContentId = "imgA";
imgRes.ContentType.Name = "imgA.jpg";
imgRes.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(imgRes);
msg.AlternateViews.Add(htmlView);
//sending prepared email
SmtpClient smtp = new SmtpClient();//It reads the SMPT params from Web.config
smtp.Send(msg);
大丈夫です。
メール形式を変更する必要がありますが、新しい形式の html ファイルを追加するにはどうすればよいですか??
新しい形式:
SmtpClient oSmtp = new SmtpClient();
SmtpMail oMail = new SmtpMail("TryIt"); //should be TryIt
SmtpServer oServer = new SmtpServer("mail.ir");
oServer.Port = 465;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
oMail.From = "";
oServer.User = "...@...";
oServer.Password = "123";
oMail.To = "@";
oMail.Subject = ;
oMail.HtmlBody =;
oSmtp.SendMail(oServer, oMail);
コード内でhtmlを使いたくないので、綺麗なhtmlファイルをデザインして送りたいです。