我可以在部署项目之前邮寄吗? [英] Could I mail before deployment the project?
本文介绍了我可以在部署项目之前邮寄吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中编写了邮件编码,但现在它不能正常工作,所以我和我的同事问过这个问题,他回答说:我们在部署之前无法发送邮件,因此无法正常工作。所以我想确认一下,是不是?
我试过以下代码
I coded for mailing in the form but now presently its not working, so i asked with my colleague about it, he replied : we cant mail before deployment it wont work. so I want to confirm it ,is it right?
I tried with this below code
public void sendMail()
{
try
{
MailMessage objeto_mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.Host = "smtp.removed.in";
client.Timeout = 10000;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("mdawood@XXREMOVEDXX", "XXREMOVEDXX");
objeto_mail.From = new MailAddress("xxx@removed.in");
objeto_mail.To.Add(new MailAddress(txtEmailId.Text));
objeto_mail.Subject = "Password Recover";
objeto_mail.Body = "Message";
client.Send(objeto_mail);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
出现错误:发送邮件失败。
there throwing an error : Failure sending mail.
推荐答案
这是在我们的项目中没有任何问题的代码:
This is the code that worked without any issues on our project:
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// Sends mail
/// </summary>
/// <param name="recipients"></param>
/// <param name="subject"></param>
/// <param name="message"></param>
/// <param name="attachments"></param>
internal override void Send(string[] recipients, string subject, string message, string[] attachments)
{
#pragma warning disable 612,618
var mail = new MailMessage();
#pragma warning restore 612,618
mail.Fields[SmtpServer] = _smtpHost;
mail.Fields[SmtpServerPort] = _smtpPort;
mail.Fields[SendUsing] = 2;
mail.Fields[SmtpUseSsl] = true;
mail.Fields[SmtpAuthenticate] = 1; // 0=anonymous, 1=basic, 2=NTLM
mail.Fields[SendUsername] = _username;
mail.Fields[SendPassword] = _password;
// set unicode encoding - it is also used for encoding email headers (not only the body)
mail.BodyEncoding = Encoding.UTF8;
// set email properties
mail.From = string.Format("{0} <{1}>", _displayName, _username);
mail.To = string.Join(";", recipients);
mail.Subject = subject;
mail.Body = message;
//mail.Priority = MailPriority.Low;
//mail.BodyFormat = MailFormat.Html;
if (attachments != null)
{
foreach (var attachment in attachments)
{
#pragma warning disable 612,618
//TODO: replace with System.Net.Mail.Attachment if supported
mail.Attachments.Add(new MailAttachment(Path.GetFullPath(attachment), MailEncoding.Base64));
#pragma warning restore 612,618
}
}
#pragma warning disable 612,618
SmtpMail.Send(mail);
#pragma warning restore 612,618
}
//////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////
///// //
您可以尝试使用它
///////
You can try to use it
这篇关于我可以在部署项目之前邮寄吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文