熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.net SMTP發送Email實例(可帶附件)

2022-06-13   來源: .NET編程 
本文為大家詳細介紹下net SMTP發送Email同時可帶附件的具體實現思路及代碼想實現的朋友可以參考下哈希望對大家有所幫助   復制代碼 代碼如下:

  
public static void sendEmail(string toAddress string emailbody)
{
var fromAddress = ConfigurationManagerAppSettings["EmailAddress"];
string fromPassword = ConfigurationManagerAppSettings["EmailPassword"]ToString();
const string subject = "Job Recommendation";
var smtp = new SmtpClient
{
Host = ConfigurationManagerAppSettings["SmtpServer"]ToString()
Port = intParse(ConfigurationManagerAppSettings["SmtpPort"])
EnableSsl = true
DeliveryMethod = SmtpDeliveryMethodNetwork
UseDefaultCredentials = false
Credentials = new NetworkCredential(fromAddress fromPassword)
};
using (var message = new MailMessage(fromAddress toAddress subject HttpUtilityHtmlEncode(emailbody)))
{
smtpSend(message);
}
}
<add key="EmailAddress" value="**********@gmailcom"/>//Email Address
<add key="EmailPassword" value="*********"/> //Emial PWD
<add key="SmtpServer" value="smtpgmailcom"/>
<add key="SmtpPort" value=""/>
<帶附件版本>
var fromAddress = "allenyinj@gmailcom";
string fromPassword = "yj";
const string subject = "CV";
var smtp = new SmtpClient
{
Host = "smtpgmailcom"
Port =
EnableSsl = true
DeliveryMethod = SmtpDeliveryMethodNetwork
UseDefaultCredentials = false
Credentials = new NetworkCredential(fromAddress fromPassword)
};
MailMessage email=new MailMessage(fromAddress "allenyinjun@gmailcom");
emailSubject = "INLINE attachment TEST";
emailIsBodyHtml = true;
string attachmentPath = "C:jpeg";
Attachment inline = new Attachment(attachmentPath);
inlineContentDispositionInline = true;
inlineContentDispositionDispositionType = DispositionTypeNamesInline;
//inlineContentId = "";
//inlineContentTypeMediaType = "image/png";
inlineContentTypeName = PathGetFileName(attachmentPath);
emailAttachmentsAdd(inline);
emailBody = "test";
smtpSend(email);
emailDispose();
//如果沒有路徑用Stream
Attachment letter = new Attachment(FileUploadLetterFileContent FileUploadLetterPostedFileContentType);
letterContentDispositionInline = true;
letterContentDispositionDispositionType = DispositionTypeNamesInline;
//inlineContentId = "";
letterContentTypeMediaType = FileUploadLetterPostedFileContentType;
letterContentTypeName = PathGetFileName(FileUploadLetterPostedFileFileName);
letterName = PathGetFileName(FileUploadLetterPostedFileFileName);


From:http://tw.wingwit.com/Article/program/net/201311/14379.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.