我刚刚创建了一个方法,用于在新用户注册时发送确认邮件
这是控制器
if (result.Succeeded)
{
var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("AFFEMS2-HEC");
UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"));
var currentUser = UserManager.FindByName(user.UserName);
var roleresult = UserManager.AddToRole(currentUser.Id, model.RoleName);
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress("my@email.lk", "Registration System "),
new System.Net.Mail.MailAddress(user.Email));
m.Subject = "Account Activation";
m.Body = string.Format("Dear {0},<BR/><BR/>Your account has been successfully created with the Higher Education Council. Please click on the link below to access your account. : <a href="{1}" title="User Email Confirm">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
m.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("##.##.##.###");
smtp.Port = ##;
smtp.Credentials = new System.Net.NetworkCredential("my@email.lk", "#######");
smtp.EnableSsl = false;
smtp.Send(m);
this.SetNotification("The User has been successfully registered. A confirmation Email has been sent to: " + user.Email, NotificationEnumeration.Success);
return RedirectToAction("View_Users", "Account");
}
现在我想要
1.将图像附加到电子邮件正文(电子邮件正文上方)
2.收缩此确认消息的激活链接(不发送大链接,它应该包含一小段文本)。
我该如何实现这些目标?
1.将图像附加到电子邮件正文(电子邮件正文上方)
由于您使用的是System.Net.Mail命名空间,因此应该能够利用Attachment类。或者,您可以在服务器上托管一个映像,并向指向该文件的MailMessage.Body
添加一个映像标记。
<img src="my-image.jpg" />
2.收缩此确认消息的激活链接(不发送大链接,它应该包含一小段文本)。
如果您真的想收缩代码,那么您需要创建自己的IUserTokenProvider接口实现。在这里,您可以定义自己创建和验证令牌或代码的方法。