我在另一个具有基础知识的站点上找到了此代码。我进行了一些更改,因为出现了错误,但是当我运行此代码时,变量页面显示为null,我不确定为什么。在掌握了基础知识之后,我将在此基础上继续工作,但我需要先进行此工作。
ViewPage:
<button class="btn btn-default" type="button" value="Email" name="Email" onclick="location.href='@Url.Action("Button1_Click", "Strategy", new {id = Model.StrategyId})'">Email</button>
后面的代码:
public void Button1_Click(object sender, EventArgs e)
{
string email = "abc@abc.com";
var page = System.Web.HttpContext.Current.CurrentHandler as Page;
page.ClientScript.RegisterStartupScript(this.GetType(), "mailto", "parent.location='mailto:" + email + "'", true);
}
我还尝试了MVC代码...此代码的唯一问题是我将无法访问所有用户密码,并且我不只是想通过Outlook发送密码,因为不是每个人都使用Outlook。理想情况下,它应该打开默认电子邮件以供用户发送。
MailMessage mailMessage = new MailMessage();
// mailMessage.From = new MailAddress(senderID);
// mailMessage.Subject = messageSubject;
// mailMessage.Body = Convert.ToString(TempData["message"]);
// mailMessage.IsBodyHtml = true;
// //mailMessage.Body = messageBody;
// if (strat.FollowUpDate == null)
// {
// mailMessage.Body = messageBody + "<br/><br/>" + "<b>Create Date: </b>" + strat.CreateDate.ToString("MM/dd/yy") + "<br/>" + "<b>Updated: </b>" + strat.Updated + "<br/>" + "<b>Customer: </b>" + strat.Customer + "<br/>" + "<b>End Product: </b>" + strat.EndProduct + "<br/>" + "<b>OSR: </b>" + strat.OSR + "<br/>" + "<b>Principal: </b>" + strat.Principal + "<br/>" + "<b>Product: </b>" + strat.Product + "<br/>" + "<b>Followup Date: </b>" + "<br/>" + "<b>Value: </b>" + strat.Value + "<br/>" + "<b>Status: </b>" + strat.Status + "<br/>" + "<b>Next Action: </b>" + strat.NextAction + "<br/>" + "<b>Latest Comments: </b>" + strat.ManagerComment + "<br/>" + "<b>History: </b>" + strat.History + "<br/>" + "<b>Group: </b>" + strat.Group;
// }
// else
// {
// mailMessage.Body = messageBody + "<br/><br/>" + "<b>Create Date:     </b>" + strat.CreateDate.ToString("MM/dd/yy") + "<br/>" + "<b>Updated:      </b>" + strat.Updated + "<br/>" + "<b>Customer:      </b>" + strat.Customer + "<br/>" + "<b>End Product:     </b>" + strat.EndProduct + "<br/>" + "<b>OSR:         </b>" + strat.OSR + "<br/>" + "<b>Principal:      </b>" + strat.Principal + "<br/>" + "<b>Product:      </b>" + strat.Product + "<br/>" + "<b>Followup Date:    </b>" + strat.FollowUpDate.Value.ToString("MM/dd/yy") + "<br/>" + "<b>Value:        </b>" + strat.Value + "<br/>" + "<b>Status:       </b>" + strat.Status + "<br/>" + "<b>Next Action:     </b>" + strat.NextAction + "<br/>" + "<b>Latest Comments:  </b>" + strat.ManagerComment + "<br/>" + "<b>History:       </b>" + strat.History + "<br/>" + "<b>Group:        </b>" + strat.Group;
// }
// mailMessage.Body = messageBody + "<br/><br/>" + "<b>Create Date: </b>" + strat.CreateDate.ToString("MM/dd/yy") + "<br/>" + "<b>Updated: </b>" + strat.Updated + "<br/>" + "<b>Customer: </b>" + strat.Customer + "<br/>" + "<b>End Product: </b>" + strat.EndProduct + "<br/>" + "<b>OSR: </b>" + strat.OSR + "<br/>" + "<b>Principal: </b>" + strat.Principal + "<br/>" + "<b>Product: </b>" + strat.Product + "<br/>" + "<b>Followup Date: </b>" + strat.FollowUpDate.Value.ToString("MM/dd/yy") + "<br/>" + "<b>Value: </b>" + strat.Value + "<br/>" + "<b>Status: </b>" + strat.Status + "<br/>" + "<b>Next Action: </b>" + strat.NextAction + "<br/>" + "<b>Latest Comments: </b>" + strat.ManagerComment + "<br/>" + "<b>History: </b>" + strat.History + "<br/>" + "<b>Group: </b>" + strat.Group;
// mailMessage.To.Add(toAddress);
// SmtpClient smtp = new SmtpClient();
// smtp.Host = "smtp.office365.com";
// smtp.EnableSsl = true;
// System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
// NetworkCred.UserName = senderID;
// NetworkCred.Password = senderPassword;
// smtp.UseDefaultCredentials = true;
// smtp.Credentials = NetworkCred;
// smtp.Port = 25;
// smtp.Send(mailMessage);