想要将邮件从一封电子邮件发送到另一封电子邮件

问题描述:


当我在客户端计算机上使用我的代码时,我想从一封电子邮件发送到另一封电子邮件,并且还想发送附件,但是我想将其放入网络后使用却没有用.网络链接为www.akdpl .com/carrer.aspx.
我也要提供我的代码

使用系统;
使用System.Collections;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Web;
使用System.Web.SessionState;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;
使用System.Diagnostics;
使用System.Text;
使用System.Configuration;
使用System.Data.OleDb;
//使用System.Xml.Linq;
使用System.Net.Mail;
使用System.Net.Mime;
使用System.Net;



受保护的void Button1_Click1(对象发送者,EventArgs e)
{
试试
{
字符串str_from_address ="contact@akdpl.com";
字符串str_name ="A K Dutta& Co. Pvt.Ltd.";
字符串str_to_address = txteid.Text;
MailMessage email_msg = new MailMessage();
email_msg.From =新的MailAddress(str_from_address,str_name);
email_msg.Sender =新的MailAddress(str_from_address,str_name);
email_msg.ReplyTo = new MailAddress(str_from_address,str_name);
email_msg.To.Add(str_to_address);
email_msg.Subject =请求确认"
email_msg.Body =非常感谢您对A K Dutta& amp; Co. Pvt.Ltd.的关注.我们将尽快与您联系"
email_msg.Priority = MailPriority.Normal;"
SmtpClient mail_client = new SmtpClient();
NetworkCredential network_cdr =新的NetworkCredential();
network_cdr.UserName = str_from_address;
network_cdr.Password =密码";
mail_client.Host ="smtp.akdpl.com";
mail_client.UseDefaultCredentials = false;
mail_client.Credentials = network_cdr;

mail_client.Send(email_msg);
//它一直工作到这里一封邮件正在发送,但之后却不起作用
sendmail();
txteid.Text ="
txtname.Text ="
txtmessage.Text ="
txtcon.Text ="
txtorg.Text ="

Response.Redirect("thanksdet.html");
}
捕获(SmtpException df)
{
Response.Write(df.ToString());
}
}




无效sendmail()
{
字符串str_from_address ="contact@akdpl.com";
字符串str_name = txtname.Text;
字符串str_to_address ="contact@akdpl.com";
MailMessage email_msg = new MailMessage();
email_msg.From =新的MailAddress(str_from_address,str_name);
email_msg.Sender =新的MailAddress(str_from_address,str_name);
email_msg.ReplyTo = new MailAddress(str_from_address,str_name);
email_msg.To.Add(str_to_address);
email_msg.Subject =请求已记录";
附件s =新附件(FileUpload1.PostedFile.FileName);
email_msg.Attachments.Add(s);

email_msg.Body =候选名称为" + txtname.Text +电子邮件ID:<" + txteid.Text +>" +出生日期:" + txtdob.Text +地址:" + txtcon.Text +电话号码:" + txtphone.Text +学历:" + txtedu.Text +申请职位:" + txtpost.文字+经历的年份:" + txtyear.Text;
email_msg.Priority = MailPriority.Normal;
SmtpClient mail_client = new SmtpClient();
NetworkCredential network_cdr =新的NetworkCredential();
network_cdr.UserName = str_from_address;
network_cdr.Password =密码";
mail_client.Host ="smtp.akdpl.com";
mail_client.UseDefaultCredentials = false;
mail_client.Credentials = network_cdr;

mail_client.Send(email_msg);
}
}
}

Hi,
I want to send an email from one to another mail and also want to send an attachment when i use my code in client machine it works, but if i used after putting it in web it didn,t work.web link is www.akdpl.com/carrer.aspx.
I am giving my code also

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Text;
using System.Configuration;
using System.Data.OleDb;
//using System.Xml.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Net;



protected void Button1_Click1(object sender, EventArgs e)
{
try
{
string str_from_address = "contact@akdpl.com";
string str_name = "A K Dutta & Co. Pvt. Ltd.";
string str_to_address = txteid.Text;
MailMessage email_msg = new MailMessage();
email_msg.From = new MailAddress(str_from_address, str_name);
email_msg.Sender = new MailAddress(str_from_address, str_name);
email_msg.ReplyTo = new MailAddress(str_from_address, str_name);
email_msg.To.Add(str_to_address);
email_msg.Subject = "Request Confirmation"
email_msg.Body = "Thank you for showing your interest in A K Dutta &amp; Co. Pvt. Ltd. .We will get back to you very soon"
email_msg.Priority = MailPriority.Normal;"
SmtpClient mail_client = new SmtpClient();
NetworkCredential network_cdr = new NetworkCredential();
network_cdr.UserName = str_from_address;
network_cdr.Password = "password";
mail_client.Host = "smtp.akdpl.com";
mail_client.UseDefaultCredentials = false;
mail_client.Credentials = network_cdr;

mail_client.Send(email_msg);
//Its Working upto Here a mail is going but after that it didn''t work
sendmail();
txteid.Text =""
txtname.Text = ""
txtmessage.Text = ""
txtcon.Text = ""
txtorg.Text = ""

Response.Redirect("thanksdet.html");
}
catch (SmtpException df)
{
Response.Write(df.ToString());
}
}




void sendmail()
{
string str_from_address = "contact@akdpl.com";
string str_name = txtname.Text;
string str_to_address = "contact@akdpl.com";
MailMessage email_msg = new MailMessage();
email_msg.From = new MailAddress(str_from_address, str_name);
email_msg.Sender = new MailAddress(str_from_address, str_name);
email_msg.ReplyTo = new MailAddress(str_from_address, str_name);
email_msg.To.Add(str_to_address);
email_msg.Subject = "Request logged";
Attachment s = new Attachment(FileUpload1.PostedFile.FileName);
email_msg.Attachments.Add(s);

email_msg.Body = "Candidate Name is " + txtname.Text + " Email Id: <" + txteid.Text + ">" + " Date of Birth : " + txtdob.Text + " Address : " + txtcon.Text + " Phone Number: " + txtphone.Text + " Education Qualification : " + txtedu.Text + " Post Applied For : " + txtpost.Text + " Year Experienced : " + txtyear.Text;
email_msg.Priority = MailPriority.Normal;
SmtpClient mail_client = new SmtpClient();
NetworkCredential network_cdr = new NetworkCredential();
network_cdr.UserName = str_from_address;
network_cdr.Password = "password";
mail_client.Host = "smtp.akdpl.com";
mail_client.UseDefaultCredentials = false;
mail_client.Credentials = network_cdr;

mail_client.Send(email_msg);
}
}
}

最可能的原因是您使用的邮件设置来自ISP,并且仅在您登录其服务器后才起作用.客户端服务器不是.无论哪种方式,这些设置都应该存在于web.config中,因此它们易于配置并且仅存储在一个位置.您的业​​务层应该有一个采用参数的方法(正文,主题,mailto(除非您也要在Web配置中指定),等等).

会发生什么,它会崩溃还是只是默默地失败?如果崩溃,则错误消息将告诉您出了什么问题.
Most likely reason is that the mail settings you''re using are from your ISP and only work when you''re logged in to their server, which the client server is not. Either way, these settings should exist in the web.config so they are easy to configure and only stored in one place. Your business layer should have a method that takes the parameters ( the body, subject, mailto ( unless you want to specify that in the web config too ), etc.

What happens, does it crash or just fail silently ? If it crashes, the error message will tell you what is wrong.