我需要检查邮件是否成功发送给指定用户,但此函数不会返回甚至不存在的电子邮件地址的错误
如何处理这个
我有一个我正在处理的应用程序,当我尝试发送电子邮件时,电子邮件发送成功,但应用程序然后使用50%的CPU直到它关闭.
这是导致问题的send方法.
public void Send()
{
if(System.String.IsNullOrEmpty(this.Server))
{
throw new PreferenceNotSetException("Server not set");
}
if(System.String.IsNullOrEmpty(this.From))
{
throw new PreferenceNotSetException("E-Mail address not set.");
}
if(System.String.IsNullOrEmpty(this.To))
{
throw new PreferenceNotSetException("Recipients E-Mail address not set.");
}
using(System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(this.From, this.To, this.Subject, this.FormattedText))
{
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.Server);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
int temp = System.Net.ServicePointManager.MaxServicePointIdleTime;
System.Net.ServicePointManager.MaxServicePointIdleTime = 1;
try
{
client.Send(message);
}
catch(System.Exception ex)
{
//For debugging only.
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
finally
{
System.Net.ServicePointManager.MaxServicePointIdleTime = temp;
//client.Dispose(); No dispose …
Run Code Online (Sandbox Code Playgroud) 嗨,这是从IIS发送电子邮件的一段代码,但我收到此错误
无法解析属性'deliveryMethod'的值.错误是:SmtpDeliveryMethodTypeConverter无法从System.String转换
这是我的代码:
MailMessage message = new MailMessage ("mostang1970@yahoo.com", "hadinematipartow@yahoo.com");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Subject = "testing of mailing list";
message.Body = "hi hadi .this email is just for test.";
message.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("127.0.0.1");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Send(message);
Run Code Online (Sandbox Code Playgroud)
这是我的web.config:
<system.net >
<mailSettings >
<smtp deliveryMethod="PickupDirectoryFromIis " >
<network host ="localhost" port ="25" defaultCredentials ="true "/>
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
请帮忙
我使用此代码在asp.net中发送电子邮件:
使用System.Net.Mail
public string SendEmail()
{
SmtpClient obj = new SmtpClient();
MailMessage Mailmsg = new MailMessage();
Mailmsg.To.Clear();
Recievers = new MailAddressCollection();
Recievers.Add(txtToAddress.Text);
SenderName = "Info";
SenderEmail = txtFromAddress.Text;
Subject = "subj";
Body = "body";
UseBcc = false;
if (UseBcc)
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.Bcc.Add(RecieverItem);
}
}
else
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.To.Add(RecieverItem);
}
}
Mailmsg.From = new MailAddress(SenderEmail, SenderName, System.Text.Encoding.UTF8);
Mailmsg.Subject = Subject;
Mailmsg.SubjectEncoding = Encoding.UTF8;
Mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
Mailmsg.IsBodyHtml = false;
obj.Host = …
Run Code Online (Sandbox Code Playgroud) namespace Binarios.admin
{
public class SendEmailGeral
{
public SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
public MailMessage msg = new MailMessage();
public void Enviar(string sendFrom, string sendTo, string subject, string body)
{
string pass = "12345";
System.Net.NetworkCredential smtpCreds = new System.Net.NetworkCredential(sendFrom, pass);
//setup SMTP Host Here
client.UseDefaultCredentials = false;
client.Credentials = smtpCreds;
client.EnableSsl = true;
MailAddress to = new MailAddress(sendTo);
MailAddress from = new MailAddress(sendFrom);
msg.IsBodyHtml = true;
msg.Subject = subject;
msg.Body = body;
msg.From = from;
msg.To.Add(to);
client.Send(msg);
}
} …
Run Code Online (Sandbox Code Playgroud) 这是我的代码
foreach (String Email in usersList)
{
if(Regex.IsMatch(Email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress AddressFrom = new MailAddress(emailFrom);
message.From = AddressFrom;
MailAddress AddressTo = new MailAddress(Email);
message.To.Add(Email);
smtpClient.Send(message);
message.Dispose();
smtpClient.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
我需要向列表中的所有用户发送电子邮件.但是,如果发生异常,则循环中断,其余电子邮件将不会发送.还有其他方法我可以这样做,所以如果无法发送电子邮件,循环会继续迭代,只是忽略失败的那些?
谢谢!
从我的localhost Web应用程序发送测试邮件时,下面提到的asp.net代码有什么问题?
错误:SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.7.1需要身份验证
string smtpAddress = "smtp.mail.yahoo.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "abcdefg@gmail.com";
string password = "12345";
string emailTo = "zyxw@gmail.com";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
using (SmtpClient smtp = new SmtpClient(smtpAddress, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用system.Net.Mail.SmtpClient发送和发送电子邮件到应用程序内部.当我在手机上运行代码时,我收到java.lang.runtimeexception错误,我无法弄清楚为什么?
我点击按钮时运行以下代码发送电子邮件.
using System;
using Android.App;
using Android.Widget;
using Android.OS;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace SendEmail
{
[Activity (Label = "SendEmail", MainLauncher = true)]
public class Activity1 : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
EditText Text = FindViewById<EditText> …
Run Code Online (Sandbox Code Playgroud) 我想做一个在C#windows应用程序中发送电子邮件的应用程序.我使用smtp服务器,但我不想设置网络凭据.所以我把它设置为true.但是我得到了错误.
SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.5.1需要身份验证.了解更多信息
这是代码:
SmtpClient oClient = new SmtpClient();
oClient.Host = "smtp.gmail.com";
oClient.Port = 25;
oClient.UseDefaultCredentials = true;
oClient.Credentials = new System.Net.NetworkCredential();
oClient.EnableSsl = true;
MailMessage oMail = new MailMessage();
oMail.To.Add(txtTo.Text.Trim());
oMail.From = new MailAddress("testmail@gmail.com");
oMail.Subject = txtSubject.Text;
oMail.Body = txtBody.Text;
oMail.IsBodyHtml = true;
oClient.Send(oMail);
MessageBox.Show("Mail Send");
Run Code Online (Sandbox Code Playgroud)
在这里我将主机设置为gmail.com,我需要使用所有电子邮件服务提供商发送和接收邮件.那么如何设置主机和端口?
我创建了这个电子邮件地址“info@mydomain.com”,我希望用户能够通过我的网站为我发送电子邮件。
这是我的代码:
MailMessage mailObject = new MailMessage("a@b.com(this is fake email)", "info@mydomain.com", "contact us", "Test message");
SmtpClient smtpC = new SmtpClient("smtp server name");
smtpC.Send(mailObject);
Run Code Online (Sandbox Code Playgroud)
问题是我不知道该写什么smtp server name
。我怎样才能找到什么是我的smtp server name
?