C# 正在尝试向文件夹发送基本电子邮件
我正试图给Folder发送一封基本的电子邮件,但是,尽管我收到了电子邮件,但尸体却完全丢失了C# 正在尝试向文件夹发送基本电子邮件,c#,visual-studio-2008,html-email,C#,Visual Studio 2008,Html Email,我正试图给Folder发送一封基本的电子邮件,但是,尽管我收到了电子邮件,但尸体却完全丢失了 private void MailReport() { string to = "arianul@gmail.com"; string From = "ArianG@lr.co.za"; string subject = "Report"; **string Body = "Dear sir ,<br> Plz Check d Attachment <
private void MailReport()
{
string to = "arianul@gmail.com";
string From = "ArianG@lr.co.za";
string subject = "Report";
**string Body = "Dear sir ,<br> Plz Check d Attachment <br><br>";**
bool send = sendMail(to, From, subject, Body);
if (send == true)
{
string CloseWindow = "alert('Mail Sent Successfully!');";
ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
}
else
{
string CloseWindow = "alert('Problem in Sending mail...try later!');";
ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
}
}
public bool sendMail(string to, string from, string subject, string body)
{
bool k = false;
try
{
MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;
AlternateView view;
SmtpClient client;
StringBuilder msgText = new StringBuilder();
view = AlternateView.CreateAlternateViewFromString(msgText.ToString(), null, "text/html");
msg.AlternateViews.Add(view);
msgText.Append("<body><br></body></html> <br><br><br> " + body);
client = new SmtpClient();
client.Host = "staging.itmaniax.co.za";
client.Send(msg);
k = true;
}
catch (Exception exe)
{
Console.WriteLine(exe.ToString());
}
return k;
}
<system.net>
<mailSettings >
<smtp deliveryMethod="specifiedPickupDirectory" from="ArianG@lr.co.za">
<network host="staging.itmaniax.co.za"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\testdump\emaildump\"/>
</smtp>
</mailSettings>
private void MailReport()
{
字符串to=”arianul@gmail.com";
字符串From=”ArianG@lr.co.za";
字符串subject=“Report”;
**string Body=“亲爱的先生,
请检查d附件
”**
bool send=sendMail(收件人、发件人、主题、正文);
if(send==true)
{
string CloseWindow=“警报('Mail Sent Successfully!”);”;
RegisterStartupScript(this.GetType(),“CloseWindow”,CloseWindow,true);
}
其他的
{
string CloseWindow=“警报('发送邮件时出现问题……请稍后再试!”);”;
RegisterStartupScript(this.GetType(),“CloseWindow”,CloseWindow,true);
}
}
public bool sendMail(字符串收件人、字符串发件人、字符串主题、字符串正文)
{
boolk=false;
尝试
{
MailMessage msg=新的MailMessage(从,到);
msg.Subject=主语;
交替视图;
SMTP客户端;
StringBuilder msgText=新建StringBuilder();
view=AlternateView.CreateAlternateView-FromString(msgText.ToString(),null,“text/html”);
msg.AlternateViews.Add(视图);
msgText.Append(“
”+正文);
client=新的SmtpClient();
client.Host=“staging.itmaniax.co.za”;
client.Send(msg);
k=真;
}
捕获(异常exe)
{
Console.WriteLine(exe.ToString());
}
返回k;
}
我觉得问题在于主体和html,就像VisualStudio-2008一样。
可能有什么建议吗?您似乎错过了:
MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;
msg.Body = body; <--- try adding this and see what happens.
MailMessage msg=新的MailMessage(从,到);
msg.Subject=主语;
msg.Body=Body 你可以试试下面的方法
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "Gmail@gmail.com";
// any address where the email will be sending
var toAddress = YourEmail.Text.ToString();
//Password of your gmail address
const string fromPassword = "Password";
// Passing the values and make a email formate to display
string subject = YourSubject.Text.ToString();
string body = "From: " + YourName.Text + "\n";
body += "Email: " + YourEmail.Text + "\n";
body += "Subject: " + YourSubject.Text + "\n";
body += "Question: \n" + Comments.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//here on button click what will done
SendMail();
DisplayMessage.Text = "Your Comments after sending the mail";
DisplayMessage.Visible = true;
YourSubject.Text = "";
YourEmail.Text = "";
YourName.Text = "";
Comments.Text = "";
}
catch (Exception) { }
}
有关更多信息,请查看
我希望这将对您有所帮助。在到达sendMail
方法时设置断点,确保body
具有值。msgText
的HTML完全错误。我会去掉HTML,只是把它放在身体里,看看它是否能通过OK。