使用C#.net-LocalMachine发送电子邮件 [英] Sending Email Using C#.net-LocalMachine
本文介绍了使用C#.net-LocalMachine发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试使用Winforms应用程序中的以下代码发送电子邮件.
用户名和密码正确无误,但在代码中已被掩盖.
我不知道我的本地计算机是否可以发送电子邮件?
但请告诉我,我需要看一下我的计算机配置(在IIS中)
Hi All,
I am trying to send email using the following piece of code in Winforms app.
Username and Password are correct and real- but have masked in the code.
I don''t know wheather my local machine has the capacity to send emails or not?
But please advise me , What I need to look at my machine Configuration(in IIS)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace EmailFunctionlaity
{
public partial class Email : Form
{
public Email()
{
InitializeComponent();
}
//All Variable Declarations
String senderAddress = string.Empty;
String receiveraddress = string.Empty;
String emailSubject = string.Empty;
String emailMessageText = string.Empty;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
private void btnEmail_Click(object sender, EventArgs e)
{
try
{
//Get the Values of Controls
senderAddress = txtSenderEmail.Text;
receiveraddress = txtReceiverEmail.Text;
emailSubject = txtSubject.Text;
emailMessageText = txtMessageBody.Text;
//Pass the Values
mail.From = new MailAddress(senderAddress, "xxxxxxxxxx", System.Text.Encoding.UTF8);
mail.To.Add(receiveraddress);
mail.Subject = emailSubject;
mail.Body = emailMessageText;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("xxxxxxx@gmail.com", "xxxxxx");
client.EnableSsl = true;
client.Send(mail);
System.Windows.Forms.MessageBox.Show("Email Sent Successfully");
}
catch (Exception mailException)
{
System.Windows.Forms.MessageBox.Show("Message Not Sent ,Error: " + mailException.Message);
throw;
}
finally
{
}
}
}
}
推荐答案
此技巧应该可以帮助您: ^ ]
如果使用正确的凭据,则第三方应用程序可以使用Gmail SMTP.
This tip should help you out: Sending an Email in C# with or without attachments: generic routine.[^]
Gmail SMTP can be used by thrid party application if correct credentials are used.
检查是否有SMTP服务器正在运行的最简单方法是打开命令提示符,然后执行以下操作:
telnet localhost 25
如果收到错误消息,则表示您没有运行任何命令(无论如何都不在默认端口上)
Simplest way to check if you have an SMTP server running is to open a command prompt and do this:
telnet localhost 25
If you get an error, then you don''t have one running (not on the default port anyway)
这篇关于使用C#.net-LocalMachine发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文